Skip to content

Hex integer literal has unexpected value #18041

Open
@inosik

Description

@inosik

Hex literals that would represent a negative number as a 32-bit value have an unexpected value when bound to a 64-bit value.

Repro steps

let a: int64 = 0xffff_ffff
let b: int64 = 0xffff_ffffL

Expected behavior

Not sure. It should either:

  • fail to compile like in VS 2019
  • a should be equal to b

Actual behavior

a has a value of -1, as if it was first parsed as a 32-bit signed integer and then converted to a 64-bit integer.

Known workarounds

  • add the L suffix to the literal
  • prepend a 0_ to force the value to be parsed as a 64-bit integer (i. e. 0x0_ffff_ffff)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-Compiler-Syntaxlexfilter, indentation and parsingBugImpact-Low(Internal MS Team use only) Describes an issue with limited impact on existing code.Regression

    Type

    Projects

    Status

    New

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions