Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge main to release/dev17.13 #17861

Merged
merged 4 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/release-notes/.FSharp.Compiler.Service/9.0.200.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
* Better ranges for CE `do!` error reporting. ([PR #17779](https://github.com/dotnet/fsharp/pull/17779))
* Better ranges for CE `return, yield, return! and yield!` error reporting. ([PR #17792](https://github.com/dotnet/fsharp/pull/17792))
* Better ranges for CE `match!`. ([PR #17789](https://github.com/dotnet/fsharp/pull/17789))
* Better ranges for CE `use` error reporting. ([PR #17811](https://github.com/dotnet/fsharp/pull/17811))

### Breaking Changes
Original file line number Diff line number Diff line change
Expand Up @@ -1805,11 +1805,8 @@ let rec TryTranslateComputationExpression
| SynExpr.LetOrUse(
isUse = true
bindings = [ SynBinding(kind = SynBindingKind.Normal; headPat = pat; expr = rhsExpr; debugPoint = spBind) ]
body = innerComp) ->
let mBind =
match spBind with
| DebugPointAtBinding.Yes m -> m
| _ -> rhsExpr.Range
body = innerComp
trivia = { LetOrUseKeyword = mBind }) ->

if ceenv.isQuery then
error (Error(FSComp.SR.tcUseMayNotBeUsedInQueries (), mBind))
Expand Down
10 changes: 3 additions & 7 deletions src/Compiler/Checking/Expressions/CheckSequenceExpressions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,10 @@ let TcSequenceExpression (cenv: TcFileState) env tpenv comp (overallTy: OverallT
// 'use x = expr in expr'
| SynExpr.LetOrUse(
isUse = true
bindings = [ SynBinding(kind = SynBindingKind.Normal; headPat = pat; expr = rhsExpr; debugPoint = spBind) ]
bindings = [ SynBinding(kind = SynBindingKind.Normal; headPat = pat; expr = rhsExpr) ]
body = innerComp
range = wholeExprMark) ->
range = wholeExprMark
trivia = { LetOrUseKeyword = mBind }) ->

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

let mBind =
match spBind with
| DebugPointAtBinding.Yes m -> m.NoteSourceConstruct(NotedSourceConstruct.Binding)
| _ -> inputExpr.Range

let inputExprMark = inputExpr.Range

let matchv, matchExpr =
Expand Down
4 changes: 2 additions & 2 deletions src/Compiler/Service/service.fs
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ module CompileHelpers =

try
f exiter
0
None
with e ->
stopProcessingRecovery e range0
1
Some e

/// Compile using the given flags. Source files names are resolved via the FileSystem API. The output file must be given by a -o flag.
let compileFromArgs (ctok, argv: string[], legacyReferenceResolver, tcImportsCapture, dynamicAssemblyCreator) =
Expand Down
3 changes: 2 additions & 1 deletion src/Compiler/Service/service.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -400,11 +400,12 @@ type public FSharpChecker =
/// Compile using the given flags. Source files names are resolved via the FileSystem API.
/// The output file must be given by a -o flag.
/// The first argument is ignored and can just be "fsc.exe".
/// The method returns the collected diagnostics, and (possibly) a terminating exception.
/// </summary>
///
/// <param name="argv">The command line arguments for the project build.</param>
/// <param name="userOpName">An optional string used for tracing compiler operations associated with this request.</param>
member Compile: argv: string[] * ?userOpName: string -> Async<FSharpDiagnostic[] * int>
member Compile: argv: string[] * ?userOpName: string -> Async<FSharpDiagnostic[] * exn option>

/// <summary>
/// Try to get type check results for a file. This looks up the results of recent type checks of the
Expand Down
17 changes: 16 additions & 1 deletion src/Compiler/SyntaxTree/ParseHelpers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1049,7 +1049,22 @@ let mkLocalBindings (mWhole, BindingSetPreAttrs(_, isRec, isUse, declsPreAttrs,
else
Some mIn)

SynExpr.LetOrUse(isRec, isUse, decls, body, mWhole, { InKeyword = mIn })
let mLetOrUse =
match decls with
| SynBinding(trivia = trivia) :: _ -> trivia.LeadingKeyword.Range
| _ -> Range.Zero

SynExpr.LetOrUse(
isRec,
isUse,
decls,
body,
mWhole,
{
LetOrUseKeyword = mLetOrUse
InKeyword = mIn
}
)

let mkDefnBindings (mWhole, BindingSetPreAttrs(_, isRec, isUse, declsPreAttrs, _bindingSetRange), attrs, vis, attrsm) =
if isUse then
Expand Down
7 changes: 6 additions & 1 deletion src/Compiler/SyntaxTree/SyntaxTrivia.fs
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,15 @@ type SynExprDotLambdaTrivia =
[<NoEquality; NoComparison>]
type SynExprLetOrUseTrivia =
{
LetOrUseKeyword: range
InKeyword: range option
}

static member Zero: SynExprLetOrUseTrivia = { InKeyword = None }
static member Zero: SynExprLetOrUseTrivia =
{
InKeyword = None
LetOrUseKeyword = Range.Zero
}

[<NoEquality; NoComparison>]
type SynExprLetOrUseBangTrivia =
Expand Down
2 changes: 2 additions & 0 deletions src/Compiler/SyntaxTree/SyntaxTrivia.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ type SynExprDotLambdaTrivia =
[<NoEquality; NoComparison>]
type SynExprLetOrUseTrivia =
{
/// The syntax range of the `let` or `use` keyword.
LetOrUseKeyword: range
/// The syntax range of the `in` keyword.
InKeyword: range option
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
namespace CompilerDirectives

open Xunit
open FSharp.Test.Compiler

module Ifdef =

let ifdefSource = """
[<EntryPoint>]
let main _ =
#if MYDEFINE1
1
#else
2
#endif
"""

[<InlineData("MYDEFINE1", 1)>]
[<InlineData("MYDEFINE", 2)>]
[<Theory>]
let ifdefTest (mydefine, expectedExitCode) =

FSharp ifdefSource
|> withDefines [mydefine]
|> compileExeAndRun
|> withExitCode expectedExitCode


let sourceExtraEndif = """
#if MYDEFINE1
printf "1"
#endif
(**)#endif(**)
0
"""

[<Fact>]
let extraEndif () =

FSharp sourceExtraEndif
|> withDefines ["MYDEFINE1"]
|> asExe
|> compile
|> withDiagnosticMessage "#endif has no matching #if in implementation file"

let sourceUnknownHash = """
module A
#ifxx
#abc
"""

[<Fact>]
let unknownHashDirectiveIsIgnored () =

FSharp sourceUnknownHash
|> compile
|> shouldSucceed
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ else ()
|> compile
|> run
|> shouldSucceed
|> withExitCode 0

[<Fact>]
let ``Respect nowarn 957 for extension method`` () =
Expand Down
Loading
Loading