From dded030d3ba58379eb7b8a4f56161687b0db7601 Mon Sep 17 00:00:00 2001 From: Vasily Kirichenko Date: Mon, 11 Dec 2017 20:46:02 +0300 Subject: [PATCH] Typecheck method args even though it's not resolved (#4105) * typecheck method args even though it's not resolved * fix tests * add a test --- src/fsharp/TypeChecker.fs | 23 ++++++----- tests/fsharp/typecheck/sigs/neg20.bsl | 40 +++++++++++++++++++ tests/fsharp/typecheck/sigs/neg67.vsbsl | 2 +- .../Tests.LanguageService.Completion.fs | 28 +++++++++++++ 4 files changed, 81 insertions(+), 12 deletions(-) diff --git a/src/fsharp/TypeChecker.fs b/src/fsharp/TypeChecker.fs index be9bd01a5..fc910a92f 100755 --- a/src/fsharp/TypeChecker.fs +++ b/src/fsharp/TypeChecker.fs @@ -9454,16 +9454,7 @@ and TcMethodApplication let uniquelyResolved = let csenv = MakeConstraintSolverEnv ContextInfo.NoContext cenv.css mMethExpr denv - let res = UnifyUniqueOverloading csenv callerArgCounts methodName ad preArgumentTypeCheckingCalledMethGroup returnTy - - match res with - | ErrorResult _ -> - match afterResolution with - | AfterResolution.DoNothing -> () - | AfterResolution.RecordResolution(_, _, _, onFailure) -> onFailure() - | _ -> () - - res |> CommitOperationResult + UnifyUniqueOverloading csenv callerArgCounts methodName ad preArgumentTypeCheckingCalledMethGroup returnTy uniquelyResolved, preArgumentTypeCheckingCalledMethGroup @@ -9496,7 +9487,7 @@ and TcMethodApplication else [domainTy] [argTys], returnTy - + let lambdaVarsAndExprs = curriedArgTys |> List.mapiSquared (fun i j ty -> mkCompGenLocal mMethExpr ("arg"+string i+string j) ty) let unnamedCurriedCallerArgs = lambdaVarsAndExprs |> List.mapSquared (fun (_, e) -> CallerArg(tyOfExpr cenv.g e, e.Range, false, e)) let namedCurriedCallerArgs = lambdaVarsAndExprs |> List.map (fun _ -> []) @@ -9530,6 +9521,16 @@ and TcMethodApplication let preArgumentTypeCheckingCalledMethGroup = preArgumentTypeCheckingCalledMethGroup |> List.map (fun cmeth -> (cmeth.Method, cmeth.CalledTyArgs, cmeth.AssociatedPropertyInfo, cmeth.UsesParamArrayConversion)) + let uniquelyResolved = + match uniquelyResolved with + | ErrorResult _ -> + match afterResolution with + | AfterResolution.DoNothing -> () + | AfterResolution.RecordResolution(_, _, _, onFailure) -> onFailure() + | _ -> () + + uniquelyResolved |> CommitOperationResult + // STEP 3. Resolve overloading /// Select the called method that's the result of overload resolution let finalCalledMeth = diff --git a/tests/fsharp/typecheck/sigs/neg20.bsl b/tests/fsharp/typecheck/sigs/neg20.bsl index d8051fd7b..9a395df9f 100644 --- a/tests/fsharp/typecheck/sigs/neg20.bsl +++ b/tests/fsharp/typecheck/sigs/neg20.bsl @@ -211,6 +211,26 @@ is not compatible with type 'int []' . +neg20.fs(183,29,183,34): typecheck error FS0001: This expression was expected to have type + 'int' +but here has type + 'obj' + +neg20.fs(183,29,183,34): typecheck error FS0001: This expression was expected to have type + 'int' +but here has type + 'obj' + +neg20.fs(183,35,183,40): typecheck error FS0001: This expression was expected to have type + 'int' +but here has type + 'obj' + +neg20.fs(183,35,183,40): typecheck error FS0001: This expression was expected to have type + 'int' +but here has type + 'obj' + neg20.fs(183,14,183,41): typecheck error FS0001: This expression was expected to have type 'unit' but here has type @@ -248,6 +268,26 @@ is not compatible with type 'string []' . +neg20.fs(189,29,189,34): typecheck error FS0001: This expression was expected to have type + 'string' +but here has type + 'obj' + +neg20.fs(189,29,189,34): typecheck error FS0001: This expression was expected to have type + 'string' +but here has type + 'obj' + +neg20.fs(189,35,189,40): typecheck error FS0001: This expression was expected to have type + 'string' +but here has type + 'obj' + +neg20.fs(189,35,189,40): typecheck error FS0001: This expression was expected to have type + 'string' +but here has type + 'obj' + neg20.fs(189,14,189,41): typecheck error FS0001: This expression was expected to have type 'unit' but here has type diff --git a/tests/fsharp/typecheck/sigs/neg67.vsbsl b/tests/fsharp/typecheck/sigs/neg67.vsbsl index 6bb131633..c501276ec 100644 --- a/tests/fsharp/typecheck/sigs/neg67.vsbsl +++ b/tests/fsharp/typecheck/sigs/neg67.vsbsl @@ -18,6 +18,6 @@ neg67.fsx(42,35,42,36): parse error FS0010: Unexpected symbol '}' in definition. neg67.fsx(41,9,41,14): typecheck error FS0001: This expression was expected to have type 'unit' but here has type - 'Async<'a>' + 'Async' neg67.fsx(30,1,41,37): typecheck error FS0003: This value is not a function and cannot be applied. diff --git a/vsintegration/tests/unittests/Tests.LanguageService.Completion.fs b/vsintegration/tests/unittests/Tests.LanguageService.Completion.fs index ed9b6160a..df4776846 100644 --- a/vsintegration/tests/unittests/Tests.LanguageService.Completion.fs +++ b/vsintegration/tests/unittests/Tests.LanguageService.Completion.fs @@ -1029,7 +1029,35 @@ for i in 0..a."] for (code, marker) in useCases do let code = prologue @ [code] AssertCtrlSpaceCompleteContains code marker [] ["field1"; "field2"] + + [] + [] + member public this.``Records.InferByFieldsInPriorMethodArguments``() = + + let prologue = + [ + "type T() =" + " new (left: float32, top: float32) = T()" + " new (left: float32, top: float32, width: float32, height: float32) = T()" + "" + "type Rect =" + " { Left: float32" + " Top: float32" + " Width: float32" + " Height: float32 }" + ] + let useCases = + [ + "let toT(original) = T(original.Left, (* MARKER*)original.)", "(* MARKER*)original.", ["Left"; "Top"; "Width"; "Height"] + "let toT(original) = T(original.Left, original.Height, (* MARKER*)original.)", "(* MARKER*)original.", ["Left"; "Top"; "Width"; "Height"] + "let toT(original) = T(original.Left, original.Height, original.Width, (* MARKER*)original.)", "(* MARKER*)original.", ["Left"; "Top"; "Width"; "Height"] + "let toT(original) = T(original.Left, original.Height, (* MARKER*)original., original.Width)", "(* MARKER*)original.", ["Left"; "Top"; "Width"; "Height"] + ] + + for (code, marker, should) in useCases do + let code = prologue @ [code] + AssertCtrlSpaceCompleteContains code marker should [] [] member this.``Completion.DetectInterfaces``() = -- GitLab