diff --git a/src/fsharp/MethodCalls.fs b/src/fsharp/MethodCalls.fs index df06f0064a..61ce01d1af 100644 --- a/src/fsharp/MethodCalls.fs +++ b/src/fsharp/MethodCalls.fs @@ -1173,6 +1173,15 @@ let AdjustCallerArgForOptional tcFieldInit eCallerMemberName (infoReader: InfoRe if isOptCallerArg then errorR(Error(FSComp.SR.tcFormalArgumentIsNotOptional(), m)) assignedArg + // For non-nullable, non-optional arguments no conversion is needed. + // We return precisely the assignedArg. This also covers the case where there + // can be a lingering permitted type mismatch between caller argument and called argument, + // specifically caller can by `byref` and called `outref`. No coercion is inserted in the + // expression tree in this case. + | NotOptional when not (isNullableTy g calledArgTy) -> + if isOptCallerArg then errorR(Error(FSComp.SR.tcFormalArgumentIsNotOptional(), m)) + assignedArg + | _ -> let callerArgExpr2 = @@ -1183,7 +1192,7 @@ let AdjustCallerArgForOptional tcFieldInit eCallerMemberName (infoReader: InfoRe if isNullableTy g calledArgTy then MakeNullableExprIfNeeded infoReader calledArgTy callerArgTy callerArgExpr m else - callerArgExpr + failwith "unreachable" // see case above | CallerSide dfltVal -> let calledArgTy = calledArg.CalledArgumentType diff --git a/tests/fsharp/tests.fs b/tests/fsharp/tests.fs index 1a2be765dc..4958c84cbe 100644 --- a/tests/fsharp/tests.fs +++ b/tests/fsharp/tests.fs @@ -254,9 +254,20 @@ module CoreTests = begin use testOkFile = fileguard cfg "test.ok" - fsc cfg "%s -o:test.exe -g" cfg.fsc_flags ["test.fsx"] + fsc cfg "%s -o:test.exe -g --langversion:4.7" cfg.fsc_flags ["test.fsx"] - singleNegTest cfg "test" + singleVersionedNegTest cfg "4.7" "test" + exec cfg ("." ++ "test.exe") "" + + testOkFile.CheckExists() + end + + begin + use testOkFile = fileguard cfg "test.ok" + + fsc cfg "%s -o:test.exe -g --langversion:5.0" cfg.fsc_flags ["test.fsx"] + + singleVersionedNegTest cfg "5.0" "test" exec cfg ("." ++ "test.exe") ""