Skip to content

Commit 8f0f018

Browse files
committed
Type checker: recover on checking binding parameter contraints
1 parent 9670f60 commit 8f0f018

File tree

2 files changed

+40
-7
lines changed

2 files changed

+40
-7
lines changed

src/Compiler/Checking/Expressions/CheckExpressions.fs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11561,12 +11561,14 @@ and TcLetBinding (cenv: cenv) isUse env containerInfo declKind tpenv (synBinds,
1156111561

1156211562
// Canonicalize constraints prior to generalization
1156311563
let denv = env.DisplayEnv
11564-
CanonicalizePartialInferenceProblem cenv.css denv synBindsRange
11565-
(checkedBinds |> List.collect (fun tbinfo ->
11566-
let (CheckedBindingInfo(_, _, _, _, explicitTyparInfo, _, _, _, tauTy, _, _, _, _, _)) = tbinfo
11567-
let (ExplicitTyparInfo(_, declaredTypars, _)) = explicitTyparInfo
11568-
let maxInferredTypars = (freeInTypeLeftToRight g false tauTy)
11569-
declaredTypars @ maxInferredTypars))
11564+
try
11565+
CanonicalizePartialInferenceProblem cenv.css denv synBindsRange
11566+
(checkedBinds |> List.collect (fun tbinfo ->
11567+
let (CheckedBindingInfo(_, _, _, _, explicitTyparInfo, _, _, _, tauTy, _, _, _, _, _)) = tbinfo
11568+
let (ExplicitTyparInfo(_, declaredTypars, _)) = explicitTyparInfo
11569+
let maxInferredTypars = (freeInTypeLeftToRight g false tauTy)
11570+
declaredTypars @ maxInferredTypars))
11571+
with RecoverableException _ -> ()
1157011572

1157111573
let lazyFreeInEnv = lazy (GeneralizationHelpers.ComputeUngeneralizableTypars env)
1157211574

tests/FSharp.Compiler.Service.Tests/TypeChecker/TypeCheckerRecoveryTests.fs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
11
module FSharp.Compiler.Service.Tests.TypeChecker.TypeCheckerRecoveryTests
22

33
open FSharp.Compiler.Service.Tests
4+
open FSharp.Compiler.Text
45
open FSharp.Test.Assert
56
open Xunit
67

8+
let assertHasSymbolUsageAtCaret name source =
9+
let context, checkResults = Checker.getCheckedResolveContext source
10+
11+
getSymbolUses checkResults
12+
|> Seq.exists (fun symbolUse ->
13+
Range.rangeContainsPos symbolUse.Range context.Pos &&
14+
symbolUse.Symbol.DisplayNameCore = name
15+
)
16+
|> shouldEqual true
17+
718
[<Fact>]
819
let ``Let 01`` () =
920
let _, checkResults = getParseAndCheckResults """
@@ -49,4 +60,24 @@ Math.Max(a,b,)
4960
"(4,0--4,14)", 503
5061
]
5162

52-
assertHasSymbolUsages ["Max"] checkResults
63+
assertHasSymbolUsages ["Max"] checkResults
64+
65+
module Constraints =
66+
[<Fact>]
67+
let ``Type 01`` () =
68+
assertHasSymbolUsageAtCaret "f" """
69+
let f (x: string) =
70+
x + 1
71+
72+
{caret}f ""
73+
"""
74+
75+
[<Fact>]
76+
let ``Type 02`` () =
77+
assertHasSymbolUsageAtCaret "M" """
78+
type T =
79+
static member M(x: string) =
80+
x + 1
81+
82+
T.M{caret} ""
83+
"""

0 commit comments

Comments
 (0)