Skip to content

Commit d59cbdf

Browse files
authored
Recover type checking inherit ctor arg expression (#8653)
* Recover type checking inherit ctor expression * Add test
1 parent 79837ec commit d59cbdf

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

src/fsharp/TypeChecker.fs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13982,7 +13982,12 @@ module MutRecBindingChecking =
1398213982
| Phase2AInherit (synBaseTy, arg, baseValOpt, m) ->
1398313983
let baseTy, tpenv = TcType cenv NoNewTypars CheckCxs ItemOccurence.Use envInstance tpenv synBaseTy
1398413984
let baseTy = baseTy |> convertToTypeWithMetadataIfPossible g
13985-
let inheritsExpr, tpenv = TcNewExpr cenv envInstance tpenv baseTy (Some synBaseTy.Range) true arg m
13985+
let inheritsExpr, tpenv =
13986+
try
13987+
TcNewExpr cenv envInstance tpenv baseTy (Some synBaseTy.Range) true arg m
13988+
with e ->
13989+
errorRecovery e m
13990+
mkUnit g m, tpenv
1398613991
let envInstance = match baseValOpt with Some baseVal -> AddLocalVal cenv.tcSink scopem baseVal envInstance | None -> envInstance
1398713992
let envNonRec = match baseValOpt with Some baseVal -> AddLocalVal cenv.tcSink scopem baseVal envNonRec | None -> envNonRec
1398813993
let innerState = (tpenv, envInstance, envStatic, envNonRec, generalizedRecBinds, preGeneralizationRecBinds, uncheckedRecBindsTable)

tests/service/Common.fs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -312,8 +312,8 @@ let getSymbolUses (source: string) =
312312
typeCheckResults.GetAllUsesOfAllSymbolsInFile() |> Async.RunSynchronously
313313

314314
let getSymbols (source: string) =
315-
getSymbolUses source
316-
|> Array.map (fun symbolUse -> symbolUse.Symbol)
315+
let symbolUses = getSymbolUses source
316+
symbolUses |> Array.map (fun symbolUse -> symbolUse.Symbol)
317317

318318

319319
let getSymbolName (symbol: FSharpSymbol) =
@@ -329,8 +329,10 @@ let getSymbolName (symbol: FSharpSymbol) =
329329

330330

331331
let assertContainsSymbolWithName name source =
332-
getSymbols source
333-
|> Array.choose getSymbolName
332+
let symbols = getSymbols source
333+
let names = symbols |> Array.choose getSymbolName
334+
335+
names
334336
|> Array.contains name
335337
|> shouldEqual true
336338

tests/service/EditorTests.fs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1361,3 +1361,14 @@ type R =
13611361
y
13621362
"""
13631363
assertContainsSymbolWithName "y" source
1364+
1365+
1366+
[<Test>]
1367+
let ``Inherit ctor arg recovery`` () =
1368+
let source = """
1369+
type T() as this =
1370+
inherit System.Exception('a', 'a')
1371+
1372+
let x = this
1373+
"""
1374+
assertContainsSymbolWithName "x" source

0 commit comments

Comments
 (0)