Skip to content

Commit 25fa115

Browse files
authored
Merge pull request #17861 from dotnet/merges/main-to-release/dev17.13
Merge main to release/dev17.13
2 parents a213e83 + a9b108c commit 25fa115

File tree

49 files changed

+575
-246
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+575
-246
lines changed

docs/release-notes/.FSharp.Compiler.Service/9.0.200.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@
1818
* Better ranges for CE `do!` error reporting. ([PR #17779](https://github.com/dotnet/fsharp/pull/17779))
1919
* Better ranges for CE `return, yield, return! and yield!` error reporting. ([PR #17792](https://github.com/dotnet/fsharp/pull/17792))
2020
* Better ranges for CE `match!`. ([PR #17789](https://github.com/dotnet/fsharp/pull/17789))
21+
* Better ranges for CE `use` error reporting. ([PR #17811](https://github.com/dotnet/fsharp/pull/17811))
2122

2223
### Breaking Changes

src/Compiler/Checking/Expressions/CheckComputationExpressions.fs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1805,11 +1805,8 @@ let rec TryTranslateComputationExpression
18051805
| SynExpr.LetOrUse(
18061806
isUse = true
18071807
bindings = [ SynBinding(kind = SynBindingKind.Normal; headPat = pat; expr = rhsExpr; debugPoint = spBind) ]
1808-
body = innerComp) ->
1809-
let mBind =
1810-
match spBind with
1811-
| DebugPointAtBinding.Yes m -> m
1812-
| _ -> rhsExpr.Range
1808+
body = innerComp
1809+
trivia = { LetOrUseKeyword = mBind }) ->
18131810

18141811
if ceenv.isQuery then
18151812
error (Error(FSComp.SR.tcUseMayNotBeUsedInQueries (), mBind))

src/Compiler/Checking/Expressions/CheckSequenceExpressions.fs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,10 @@ let TcSequenceExpression (cenv: TcFileState) env tpenv comp (overallTy: OverallT
232232
// 'use x = expr in expr'
233233
| SynExpr.LetOrUse(
234234
isUse = true
235-
bindings = [ SynBinding(kind = SynBindingKind.Normal; headPat = pat; expr = rhsExpr; debugPoint = spBind) ]
235+
bindings = [ SynBinding(kind = SynBindingKind.Normal; headPat = pat; expr = rhsExpr) ]
236236
body = innerComp
237-
range = wholeExprMark) ->
237+
range = wholeExprMark
238+
trivia = { LetOrUseKeyword = mBind }) ->
238239

239240
let bindPatTy = NewInferenceType g
240241
let inputExprTy = NewInferenceType g
@@ -252,11 +253,6 @@ let TcSequenceExpression (cenv: TcFileState) env tpenv comp (overallTy: OverallT
252253
let envinner = { envinner with eIsControlFlow = true }
253254
tcSequenceExprBody envinner genOuterTy tpenv innerComp
254255

255-
let mBind =
256-
match spBind with
257-
| DebugPointAtBinding.Yes m -> m.NoteSourceConstruct(NotedSourceConstruct.Binding)
258-
| _ -> inputExpr.Range
259-
260256
let inputExprMark = inputExpr.Range
261257

262258
let matchv, matchExpr =

src/Compiler/Service/service.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ module CompileHelpers =
7272

7373
try
7474
f exiter
75-
0
75+
None
7676
with e ->
7777
stopProcessingRecovery e range0
78-
1
78+
Some e
7979

8080
/// Compile using the given flags. Source files names are resolved via the FileSystem API. The output file must be given by a -o flag.
8181
let compileFromArgs (ctok, argv: string[], legacyReferenceResolver, tcImportsCapture, dynamicAssemblyCreator) =

src/Compiler/Service/service.fsi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,11 +400,12 @@ type public FSharpChecker =
400400
/// Compile using the given flags. Source files names are resolved via the FileSystem API.
401401
/// The output file must be given by a -o flag.
402402
/// The first argument is ignored and can just be "fsc.exe".
403+
/// The method returns the collected diagnostics, and (possibly) a terminating exception.
403404
/// </summary>
404405
///
405406
/// <param name="argv">The command line arguments for the project build.</param>
406407
/// <param name="userOpName">An optional string used for tracing compiler operations associated with this request.</param>
407-
member Compile: argv: string[] * ?userOpName: string -> Async<FSharpDiagnostic[] * int>
408+
member Compile: argv: string[] * ?userOpName: string -> Async<FSharpDiagnostic[] * exn option>
408409

409410
/// <summary>
410411
/// Try to get type check results for a file. This looks up the results of recent type checks of the

src/Compiler/SyntaxTree/ParseHelpers.fs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1049,7 +1049,22 @@ let mkLocalBindings (mWhole, BindingSetPreAttrs(_, isRec, isUse, declsPreAttrs,
10491049
else
10501050
Some mIn)
10511051

1052-
SynExpr.LetOrUse(isRec, isUse, decls, body, mWhole, { InKeyword = mIn })
1052+
let mLetOrUse =
1053+
match decls with
1054+
| SynBinding(trivia = trivia) :: _ -> trivia.LeadingKeyword.Range
1055+
| _ -> Range.Zero
1056+
1057+
SynExpr.LetOrUse(
1058+
isRec,
1059+
isUse,
1060+
decls,
1061+
body,
1062+
mWhole,
1063+
{
1064+
LetOrUseKeyword = mLetOrUse
1065+
InKeyword = mIn
1066+
}
1067+
)
10531068

10541069
let mkDefnBindings (mWhole, BindingSetPreAttrs(_, isRec, isUse, declsPreAttrs, _bindingSetRange), attrs, vis, attrsm) =
10551070
if isUse then

src/Compiler/SyntaxTree/SyntaxTrivia.fs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,15 @@ type SynExprDotLambdaTrivia =
8585
[<NoEquality; NoComparison>]
8686
type SynExprLetOrUseTrivia =
8787
{
88+
LetOrUseKeyword: range
8889
InKeyword: range option
8990
}
9091

91-
static member Zero: SynExprLetOrUseTrivia = { InKeyword = None }
92+
static member Zero: SynExprLetOrUseTrivia =
93+
{
94+
InKeyword = None
95+
LetOrUseKeyword = Range.Zero
96+
}
9297

9398
[<NoEquality; NoComparison>]
9499
type SynExprLetOrUseBangTrivia =

src/Compiler/SyntaxTree/SyntaxTrivia.fsi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ type SynExprDotLambdaTrivia =
129129
[<NoEquality; NoComparison>]
130130
type SynExprLetOrUseTrivia =
131131
{
132+
/// The syntax range of the `let` or `use` keyword.
133+
LetOrUseKeyword: range
132134
/// The syntax range of the `in` keyword.
133135
InKeyword: range option
134136
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
namespace CompilerDirectives
2+
3+
open Xunit
4+
open FSharp.Test.Compiler
5+
6+
module Ifdef =
7+
8+
let ifdefSource = """
9+
[<EntryPoint>]
10+
let main _ =
11+
#if MYDEFINE1
12+
1
13+
#else
14+
2
15+
#endif
16+
"""
17+
18+
[<InlineData("MYDEFINE1", 1)>]
19+
[<InlineData("MYDEFINE", 2)>]
20+
[<Theory>]
21+
let ifdefTest (mydefine, expectedExitCode) =
22+
23+
FSharp ifdefSource
24+
|> withDefines [mydefine]
25+
|> compileExeAndRun
26+
|> withExitCode expectedExitCode
27+
28+
29+
let sourceExtraEndif = """
30+
#if MYDEFINE1
31+
printf "1"
32+
#endif
33+
(**)#endif(**)
34+
0
35+
"""
36+
37+
[<Fact>]
38+
let extraEndif () =
39+
40+
FSharp sourceExtraEndif
41+
|> withDefines ["MYDEFINE1"]
42+
|> asExe
43+
|> compile
44+
|> withDiagnosticMessage "#endif has no matching #if in implementation file"
45+
46+
let sourceUnknownHash = """
47+
module A
48+
#ifxx
49+
#abc
50+
"""
51+
52+
[<Fact>]
53+
let unknownHashDirectiveIsIgnored () =
54+
55+
FSharp sourceUnknownHash
56+
|> compile
57+
|> shouldSucceed

tests/FSharp.Compiler.ComponentTests/ConstraintSolver/MemberConstraints.fs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ else ()
4545
|> compile
4646
|> run
4747
|> shouldSucceed
48-
|> withExitCode 0
4948

5049
[<Fact>]
5150
let ``Respect nowarn 957 for extension method`` () =

0 commit comments

Comments
 (0)