From 287b3ce7000b614c2975643c979098fc55c45c6c Mon Sep 17 00:00:00 2001 From: Eugene Auduchinok Date: Tue, 17 Feb 2026 15:14:17 +0100 Subject: [PATCH 1/2] Type checker: recover on argument/overload checking --- .../Checking/Expressions/CheckExpressions.fs | 18 ++++++++- .../TypeChecker/TypeCheckerRecoveryTests.fs | 38 +++++++++++++++++++ 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/src/Compiler/Checking/Expressions/CheckExpressions.fs b/src/Compiler/Checking/Expressions/CheckExpressions.fs index 3d93b2c526d..1d27f579ee4 100644 --- a/src/Compiler/Checking/Expressions/CheckExpressions.fs +++ b/src/Compiler/Checking/Expressions/CheckExpressions.fs @@ -689,6 +689,20 @@ let UnifyFunctionType extraInfo (cenv: cenv) denv mFunExpr ty = | Some argm -> error (NotAFunction(denv, ty, mFunExpr, argm)) | None -> error (FunctionExpected(denv, ty, mFunExpr)) +let UnifyFunctionTypeAndRecover extraInfo (cenv: cenv) denv mFunExpr ty = + match UnifyFunctionTypeUndoIfFailed cenv denv mFunExpr ty with + | ValueSome res -> res + | ValueNone -> + match extraInfo with + | Some argm -> errorR (NotAFunction(denv, ty, mFunExpr, argm)) + | None -> errorR (FunctionExpected(denv, ty, mFunExpr)) + + let g = cenv.g + let domainTy = NewInferenceType g + let resultTy = NewInferenceType g + domainTy, resultTy + + let ReportImplicitlyIgnoredBoolExpression denv m ty expr = let checkExpr m expr = match stripDebugPoints expr with @@ -10034,7 +10048,7 @@ and TcMethodApplication_UniqueOverloadInference // type we assume the number of arguments is just "1". | None, _ -> - let domainTy, returnTy = UnifyFunctionType None cenv denv mMethExpr exprTy.Commit + let domainTy, returnTy = UnifyFunctionTypeAndRecover None cenv denv mMethExpr exprTy.Commit let argTys = if isUnitTy g domainTy then [] else tryDestRefTupleTy g domainTy // Only apply this rule if a candidate method exists with this number of arguments let argTys = @@ -10114,7 +10128,7 @@ and TcMethodApplication_CheckArguments let curriedArgTys, returnTy = UnifyMatchingSimpleArgumentTypes cenv env exprTy.Commit calledMeth mMethExpr mItem curriedArgTys, paramNamesIfFeatureEnabled g calledMeth, MustEqual returnTy | _ -> - let domainTy, returnTy = UnifyFunctionType None cenv denv mMethExpr exprTy.Commit + let domainTy, returnTy = UnifyFunctionTypeAndRecover None cenv denv mMethExpr exprTy.Commit let argTys = if isUnitTy g domainTy then [] else tryDestRefTupleTy g domainTy // Only apply this rule if a candidate method exists with this number of arguments let argTys, argNames = diff --git a/tests/FSharp.Compiler.Service.Tests/TypeChecker/TypeCheckerRecoveryTests.fs b/tests/FSharp.Compiler.Service.Tests/TypeChecker/TypeCheckerRecoveryTests.fs index 1f9dd815c80..3f9d13622e6 100644 --- a/tests/FSharp.Compiler.Service.Tests/TypeChecker/TypeCheckerRecoveryTests.fs +++ b/tests/FSharp.Compiler.Service.Tests/TypeChecker/TypeCheckerRecoveryTests.fs @@ -81,3 +81,41 @@ type T = T.M{caret} "" """ + +module Expressions = + [] + let ``Method type 01`` () = + assertHasSymbolUsageAtCaret "ToString" """ +if true then + "".ToString{caret} +""" + + + [] + let ``Method type 02`` () = + assertHasSymbolUsageAtCaret "M" """ +type T = + static member M() = "" + +if true then + T.M{caret} +""" + + [] + let ``Method type 03`` () = + assertHasSymbolUsageAtCaret "M" """ +type T = + static member M(i: int) = "" + static member M(s: string) = "" + +if true then + T.M{caret} +""" + + [] + let ``Method type 04`` () = + assertHasSymbolUsageAtCaret "GetHashCode" """ +let o: obj = null +if true then + o.GetHashCode{caret} +""" From 0b7d0ad4f77d9e38661a3a9f65fdc2f64f2de03d Mon Sep 17 00:00:00 2001 From: Eugene Auduchinok Date: Tue, 17 Feb 2026 15:20:17 +0100 Subject: [PATCH 2/2] Release notes --- docs/release-notes/.FSharp.Compiler.Service/10.0.300.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/release-notes/.FSharp.Compiler.Service/10.0.300.md b/docs/release-notes/.FSharp.Compiler.Service/10.0.300.md index 6a30bf55364..a2b35114fd8 100644 --- a/docs/release-notes/.FSharp.Compiler.Service/10.0.300.md +++ b/docs/release-notes/.FSharp.Compiler.Service/10.0.300.md @@ -17,6 +17,7 @@ ### Added * FSharpType: add ImportILType ([PR #19300](https://github.com/dotnet/fsharp/pull/19300)) +* Type checker: recover on argument/overload checking ([PR #19314](https://github.com/dotnet/fsharp/pull/19314)) ### Changed