Skip to content

Commit 6d6e689

Browse files
authored
Merge pull request #17954 from dotnet/merges/main-to-release/dev17.13
Merge main to release/dev17.13
2 parents 6dcaa8d + abce1c5 commit 6d6e689

File tree

2 files changed

+58
-7
lines changed

2 files changed

+58
-7
lines changed

src/Compiler/Facilities/prim-lexing.fs

+2-2
Original file line numberDiff line numberDiff line change
@@ -238,13 +238,13 @@ type internal Position =
238238
Position(x.FileIndex, x.Line, x.OriginalLine, x.StartOfLineAbsoluteOffset, x.StartOfLineAbsoluteOffset - 1)
239239

240240
member x.ApplyLineDirective(fileIdx, line) =
241-
Position(fileIdx, line, x.OriginalLine, x.AbsoluteOffset, x.AbsoluteOffset)
241+
Position(fileIdx, line, x.OriginalLine + 1, x.AbsoluteOffset, x.AbsoluteOffset)
242242

243243
override p.ToString() = $"({p.Line},{p.Column})"
244244

245245
static member Empty = Position()
246246

247-
static member FirstLine fileIdx = Position(fileIdx, 1, 0, 0, 0)
247+
static member FirstLine fileIdx = Position(fileIdx, 1, 1, 0, 0)
248248

249249
type internal LexBufferFiller<'Char> = LexBuffer<'Char> -> unit
250250

tests/FSharp.Compiler.ComponentTests/CompilerDirectives/Line.fs

+56-5
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,20 @@ namespace CompilerDirectives
22

33
open Microsoft.FSharp.Control
44
open Xunit
5-
open FSharp.Test.Compiler
5+
open Internal.Utilities
6+
open FSharp.Compiler
67
open FSharp.Compiler.CodeAnalysis
7-
open FSharp.Compiler.Text
8+
open FSharp.Compiler.DiagnosticsLogger
9+
open FSharp.Compiler.Features
10+
open FSharp.Compiler.Lexhelp
811
open FSharp.Compiler.Syntax
12+
open FSharp.Compiler.Text
13+
open FSharp.Compiler.UnicodeLexing
914

1015
module Line =
1116

12-
let checker = FSharpChecker.Create()
13-
1417
let parse (source: string) =
18+
let checker = FSharpChecker.Create()
1519
let langVersion = "preview"
1620
let sourceFileName = __SOURCE_FILE__
1721
let parsingOptions =
@@ -63,4 +67,51 @@ printfn ""
6367
| ParsedInput.SigFile _ -> failwith "unexpected: sig file"
6468
if exprRange <> expectedRange then
6569
failwith $"case{case}: expected: {expectedRange}, found {exprRange}"
66-
70+
71+
72+
73+
74+
75+
let private getTokens sourceText =
76+
let langVersion = LanguageVersion.Default
77+
let lexargs =
78+
mkLexargs (
79+
[],
80+
IndentationAwareSyntaxStatus(true, false),
81+
LexResourceManager(),
82+
[],
83+
DiscardErrorsLogger,
84+
PathMap.empty,
85+
true
86+
)
87+
let lexbuf = StringAsLexbuf(true, langVersion, None, sourceText)
88+
resetLexbufPos "test.fs" lexbuf
89+
let tokenizer _ =
90+
let t = Lexer.token lexargs true lexbuf
91+
let p = lexbuf.StartPos
92+
t, FileIndex.fileOfFileIndex p.FileIndex, p.OriginalLine, p.Line
93+
let isNotEof(t,_,_,_) = match t with Parser.EOF _ -> false | _ -> true
94+
Seq.initInfinite tokenizer |> Seq.takeWhile isNotEof |> Seq.toList
95+
96+
let private code = """
97+
1
98+
#line 5 "other.fs"
99+
2
100+
#line 10 "test.fs"
101+
3
102+
"""
103+
104+
let private expected = [
105+
"test.fs", 2, 2
106+
"other.fs", 4, 5
107+
"test.fs", 6, 10
108+
]
109+
110+
[<Fact>]
111+
let checkOriginalLineNumbers() =
112+
let tokens = getTokens code
113+
Assert.Equal(expected.Length, tokens.Length)
114+
for ((e_idx, e_oLine, e_line), (_, idx, oLine, line)) in List.zip expected tokens do
115+
Assert.Equal(e_idx, idx)
116+
Assert.Equal(e_oLine, oLine)
117+
Assert.Equal(e_line, line)

0 commit comments

Comments
 (0)