Skip to content
Open
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
2 changes: 2 additions & 0 deletions docs/release-notes/.FSharp.Compiler.Service/11.0.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

### Added

* Type checker: recover on checking binding parameter constraints ([#19046](https://github.com/dotnet/fsharp/pull/19046))

### Changed

* Parallel compilation stabilised and enabled by default ([PR #18998](https://github.com/dotnet/fsharp/pull/18998))
Expand Down
14 changes: 8 additions & 6 deletions src/Compiler/Checking/Expressions/CheckExpressions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -11561,12 +11561,14 @@ and TcLetBinding (cenv: cenv) isUse env containerInfo declKind tpenv (synBinds,

// Canonicalize constraints prior to generalization
let denv = env.DisplayEnv
CanonicalizePartialInferenceProblem cenv.css denv synBindsRange
(checkedBinds |> List.collect (fun tbinfo ->
let (CheckedBindingInfo(_, _, _, _, explicitTyparInfo, _, _, _, tauTy, _, _, _, _, _)) = tbinfo
let (ExplicitTyparInfo(_, declaredTypars, _)) = explicitTyparInfo
let maxInferredTypars = (freeInTypeLeftToRight g false tauTy)
declaredTypars @ maxInferredTypars))
try
CanonicalizePartialInferenceProblem cenv.css denv synBindsRange
(checkedBinds |> List.collect (fun tbinfo ->
let (CheckedBindingInfo(_, _, _, _, explicitTyparInfo, _, _, _, tauTy, _, _, _, _, _)) = tbinfo
let (ExplicitTyparInfo(_, declaredTypars, _)) = explicitTyparInfo
let maxInferredTypars = (freeInTypeLeftToRight g false tauTy)
declaredTypars @ maxInferredTypars))
with RecoverableException _ -> ()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add more explanation as code comment why it is fine to gave an all-catching try block here, this might not be obvious for future readers.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's just like in other places where it felt safe to recover and continue To be honest, I don't even know what to write in such a comment so it wouldn't be just stating that we're recovering...


let lazyFreeInEnv = lazy (GeneralizationHelpers.ComputeUngeneralizableTypars env)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
module FSharp.Compiler.Service.Tests.TypeChecker.TypeCheckerRecoveryTests

open FSharp.Compiler.Service.Tests
open FSharp.Compiler.Text
open FSharp.Test.Assert
open Xunit

let assertHasSymbolUsageAtCaret name source =
let context, checkResults = Checker.getCheckedResolveContext source

getSymbolUses checkResults
|> Seq.exists (fun symbolUse ->
Range.rangeContainsPos symbolUse.Range context.Pos &&
symbolUse.Symbol.DisplayNameCore = name
)
|> shouldEqual true

[<Fact>]
let ``Let 01`` () =
let _, checkResults = getParseAndCheckResults """
Expand Down Expand Up @@ -49,4 +60,24 @@ Math.Max(a,b,)
"(4,0--4,14)", 503
]

assertHasSymbolUsages ["Max"] checkResults
assertHasSymbolUsages ["Max"] checkResults

module Constraints =
[<Fact>]
let ``Type 01`` () =
assertHasSymbolUsageAtCaret "f" """
let f (x: string) =
x + 1

{caret}f ""
"""

[<Fact>]
let ``Type 02`` () =
assertHasSymbolUsageAtCaret "M" """
type T =
static member M(x: string) =
x + 1

T.M{caret} ""
"""
4 changes: 3 additions & 1 deletion tests/fsharp/typecheck/sigs/neg68.bsl
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@

neg68.fsx(71,46,71,47): parse error FS0010: Unexpected symbol ')' in binding. Expected incomplete structured construct at or before this point or other token.
neg68.fsx(138,15,138,16): typecheck info FS3370: The use of '!' from the F# library is deprecated. See https://aka.ms/fsharp-refcell-ops. For example, please change '!cell' to 'cell.Value'.

neg68.fsx(158,24,158,26): typecheck info FS3370: The use of ':=' from the F# library is deprecated. See https://aka.ms/fsharp-refcell-ops. For example, please change 'cell := expr' to 'cell.Value <- expr'.
2 changes: 1 addition & 1 deletion tests/fsharp/typecheck/sigs/neg68.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ type sRealTime
[<Measure>]
type pixels

let G = 6.67e-11<m ^ 3 / (kg s^2))>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its not really a "neg" test anymore, isn't it?
Imo you might as well remove it, as I do not see it it testing anything.

If you kept the superfluous paren to maintain this being a neg test, is the recovery same/better ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it felt like this test doesn't test anything useful given how the errors flow in that file. I can remove it for sure.

let G = 6.67e-11<m ^ 3 / (kg s^2)>
let m_per_AU = 149597870691.0<m/AU>
let AU_per_m = 1.0/m_per_AU
let Pixels_per_AU = 200.0<pixels/AU>
Expand Down
27 changes: 2 additions & 25 deletions tests/fsharp/typecheck/sigs/neg68.vsbsl
Original file line number Diff line number Diff line change
@@ -1,26 +1,3 @@
neg68.fsx(138,15,138,16): typecheck info FS3370: The use of '!' from the F# library is deprecated. See https://aka.ms/fsharp-refcell-ops. For example, please change '!cell' to 'cell.Value'.

neg68.fsx(71,46,71,47): parse error FS0010: Unexpected symbol ')' in binding. Expected incomplete structured construct at or before this point or other token.

neg68.fsx(71,32,71,33): typecheck error FS0062: This construct is for ML compatibility. Consider using the '+' operator instead. This may require a type annotation to indicate it acts on strings. This message can be disabled using '--nowarn:62' or '#nowarn "62"'.

neg68.fsx(71,30,71,46): typecheck error FS0001: This expression was expected to have type
'float'
but here has type
'string'

neg68.fsx(71,30,71,31): typecheck error FS1133: No constructors are available for the type 'm'

neg68.fsx(71,43,71,44): typecheck error FS0062: This construct is for ML compatibility. Consider using the '+' operator instead. This may require a type annotation to indicate it acts on strings. This message can be disabled using '--nowarn:62' or '#nowarn "62"'.

neg68.fsx(71,39,71,45): typecheck error FS0001: The type 'string' does not match the type 'int'

neg68.fsx(71,39,71,41): typecheck error FS1133: No constructors are available for the type 'kg'

neg68.fsx(71,44,71,45): typecheck error FS0001: This expression was expected to have type
'string'
but here has type
'int'

neg68.fsx(123,40,123,41): typecheck error FS0001: The type 'bool' does not match the type 'float<'u>'

neg68.fsx(123,38,123,39): typecheck error FS0043: The type 'bool' does not match the type 'float<'u>'
neg68.fsx(158,24,158,26): typecheck info FS3370: The use of ':=' from the F# library is deprecated. See https://aka.ms/fsharp-refcell-ops. For example, please change 'cell := expr' to 'cell.Value <- expr'.
Loading