Skip to content

Internal: Line directives can lead to invalid ranges  #17529

@Martin521

Description

@Martin521

For the following source files

Case 1

module A
#line 1 "xyz.fs"
(
printfn ""
)

Case 2

module A
(
#line 1 "xyz.fs"
printfn ""
)

Case 3

module A
(
#line 1 "xyz.fs"
)

The range of the only expression in module A is

  • Case 1: (1,0--3,1) in xyz.fs
  • Case 2: (2,0--2,1) in the source file
  • Case 3: (2,0--134217729,1) in the source file

Case 1 is correct. Case 2 is probably acceptable.
Case 3, however, is blocking my work on "scoped nowarn".
This was not easy to find, but I think I can fix it. I just want to do it in a PR separate from "scoped nowarn", therefore this issue.
(If you are wondering: 134217729 is 2**27+1, and the range line offset has 27 bits. So there must be some wrong difference somewhere.)
(Source code like the above exists in the fsyacc-generated xxpars.fs files.)

Repro steps

Parse the above sources with ApplyLineDirectives = true and check the ranges in the AST.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Done

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions