Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve compiler error message for failed overload resolution #6596

Merged
merged 96 commits into from
Feb 19, 2020
Merged
Show file tree
Hide file tree
Changes from 95 commits
Commits
Show all changes
96 commits
Select commit Hold shift + click to select a range
1f68b17
migrate (as a separate copy) fsharpqa tests that are going to be impa…
smoothdeveloper Apr 30, 2019
d0630a3
update the .bsl files
smoothdeveloper Apr 30, 2019
c01329f
remove comments that are handled by baseline files, update baseline f…
smoothdeveloper Apr 30, 2019
56fbe7a
remove the migrated tests from fsharpqa tests
smoothdeveloper Apr 30, 2019
632f8ee
need to be more careful when migrating those
smoothdeveloper Apr 30, 2019
bcd4068
testing if running the test with .fs instead of .fsx makes them work …
smoothdeveloper Apr 30, 2019
55bc729
exclude migrated fsharpqa from dotnet core run
smoothdeveloper Apr 30, 2019
823c53a
sample test in fsharpqa (can't run locally for now)
smoothdeveloper Apr 20, 2019
9671f33
trying to make it green now.
smoothdeveloper Apr 21, 2019
2eb3b56
checking if this path is covered by a test, trying to identify how to…
smoothdeveloper Apr 21, 2019
7781572
* [MethodCalls.fs] Defining CallerArgs<'T> in, this replaces passing …
smoothdeveloper Apr 22, 2019
81ef5f2
bit of refactoring of error message building logic during failed over…
smoothdeveloper Apr 23, 2019
69cbc05
(buildfix) harmonizing .fsi/.fs right before commit doesn't always wo…
smoothdeveloper Apr 23, 2019
9f47fee
trying to check what kind of things break loose when I change this
smoothdeveloper Apr 24, 2019
41b219c
(minor) [ConstraintSolver.fs] revert space mishapps to reduce diff, p…
smoothdeveloper Apr 24, 2019
7f73826
toward displaying the argument names properly (may fail some fsharpqa…
smoothdeveloper Apr 24, 2019
0904de6
missing Resharper's Ctrl+Alt+V "introduce variable" refactoring @audu…
smoothdeveloper Apr 24, 2019
f1eadef
pretty print unresolved overloads without all the type submsumption p…
smoothdeveloper Apr 25, 2019
9eb633a
Overload resolution error messages: things display like I want in fsi…
smoothdeveloper Apr 25, 2019
b49d285
adjust message for candidates overload
smoothdeveloper Apr 26, 2019
6aaf2dd
Hijack the split phase for UnresolvedOverloading, remove the match on…
smoothdeveloper Apr 29, 2019
f66e082
updating existing failing baseline files that looks correct to me
smoothdeveloper Apr 29, 2019
3f03717
quickfix for update.base.line.with.actuals.fsx so that it skips missi…
smoothdeveloper Apr 29, 2019
389a804
(minor) minimize diff, typos, comments
smoothdeveloper Apr 30, 2019
dbe7a37
fix vsintegration tests affected by overload error message changes
smoothdeveloper Apr 30, 2019
f8e7428
merge issue unused variable warning
smoothdeveloper Apr 30, 2019
c51e25c
update the 12 fsharpqa migrated baseline with new error messages
smoothdeveloper Apr 30, 2019
41f57e1
(minor) baseline update script
smoothdeveloper Apr 30, 2019
51e3a0e
move System.Convert.ToString and System.Threading.Tasks.Task.Run test…
smoothdeveloper Apr 30, 2019
76c9c59
* moving 3 fsharpqa tests to new test suite
smoothdeveloper May 2, 2019
b00175f
consolidate all string building logic in CompileOps.fs, fix remaining…
smoothdeveloper May 2, 2019
e64f4f6
update base lines
smoothdeveloper May 2, 2019
db5df8d
remove the migrated tests from fsharpqa
smoothdeveloper May 2, 2019
dce9b92
fix vstest error message
smoothdeveloper May 2, 2019
36b6a13
fix env.lst, removed wrong one...
smoothdeveloper May 2, 2019
bf4ee09
update baselines of remaining tests
smoothdeveloper May 2, 2019
f45a218
adding one simple test with many overloads
smoothdeveloper May 2, 2019
ce65f30
appropriate /// comments on `CalledMeth` constructor arguments
smoothdeveloper May 2, 2019
372a375
minimize diff / formatting
smoothdeveloper May 2, 2019
db26509
trim unused code
smoothdeveloper May 2, 2019
46174af
add simple test, one message is interesting, mentioning parameter cou…
smoothdeveloper May 3, 2019
c2120f6
comment flaky test for now
smoothdeveloper May 3, 2019
ec6089c
code review on the `coerceExpr` function from @tihan, we can discard …
smoothdeveloper May 8, 2019
4f51ad4
code formatting remarks on ConstraintSolver.fs/fsi
smoothdeveloper May 14, 2019
2d27e63
(minor) formatting
smoothdeveloper May 14, 2019
28f46ca
format known argument type / updating .bsl
smoothdeveloper May 16, 2019
20abb54
update missing baseline
smoothdeveloper May 16, 2019
c5de0ac
update missing baselines
smoothdeveloper May 16, 2019
e08db81
update missing baseline
smoothdeveloper May 16, 2019
628d8bc
minor: make TTrait better in debugger display
smoothdeveloper Aug 24, 2019
e2bc962
[wip] pass TraitConstraintInfo around failed overload resolution erro…
smoothdeveloper Aug 24, 2019
4f70822
minimize diff
smoothdeveloper Aug 27, 2019
138267f
signature file mismatch
smoothdeveloper Aug 27, 2019
ebf60fa
removing duplicate in fscomp.txt
smoothdeveloper Dec 27, 2019
20a4cff
surfacing initial bits of TraitConstraintInfo, roughly for now
smoothdeveloper Dec 27, 2019
5bb714a
formatting types of known argument in one go, the formatting is still…
smoothdeveloper Jan 12, 2020
59f82b1
rework of overload failure message to prettify *ALL* types in a singl…
smoothdeveloper Jan 15, 2020
7b8fdfc
fixup the tests and add two tests
smoothdeveloper Jan 15, 2020
a956bce
updating baselines that got tighter.
smoothdeveloper Jan 16, 2020
8b102a0
simplify handling of TraitConstraintInfo
smoothdeveloper Jan 16, 2020
8543f80
naming couple of fields and turning a property to a methods as it tri…
smoothdeveloper Jan 17, 2020
c5739e7
comments in the assembling of overload resolution error message
smoothdeveloper Jan 17, 2020
ade30f5
Add information about which argument doesn't match
smoothdeveloper Jan 19, 2020
207a584
minor updates to testguide and devguide
smoothdeveloper Jan 19, 2020
7ca85af
fix PrimitiveConstraints.``Invalid object constructor`` test
smoothdeveloper Jan 19, 2020
723a293
fix(?) salsa tests
smoothdeveloper Jan 19, 2020
f0be1bb
minimize diff
smoothdeveloper Jan 19, 2020
373f0f3
put back tests under !FSHARP_SUITE_DRIVES_CORECLR_TESTS
smoothdeveloper Jan 19, 2020
4c7d525
missing updated message
smoothdeveloper Jan 19, 2020
5408e4f
minor adjustments to TESTGUIDE.md
smoothdeveloper Jan 19, 2020
e8dc47b
return type was missing prettifying in prettyLayoutsOfUnresolvedOverl…
smoothdeveloper Jan 19, 2020
99097a6
address code review nits / minimize diff / add comment on PrettifyDis…
smoothdeveloper Jan 22, 2020
99c1230
minimize diff
smoothdeveloper Jan 22, 2020
9f20d8f
proposed work around the flaky error message until https://github.com…
smoothdeveloper Jan 22, 2020
45be9dc
fixing baselines of new tests from master
smoothdeveloper Jan 22, 2020
18cbe3c
sisyphus round of baseline update
smoothdeveloper Jan 22, 2020
c7d8b13
removing type which isn't in use and popped back up after rebase
smoothdeveloper Jan 22, 2020
209cc6c
minimize diff
smoothdeveloper Jan 23, 2020
1f17d51
tidy inconsistent tuple literal
smoothdeveloper Jan 23, 2020
90defce
* removing TTrait properties that end up not being used
smoothdeveloper Jan 23, 2020
d99015f
minimize diff
smoothdeveloper Jan 23, 2020
3176d37
minimize diff
smoothdeveloper Jan 23, 2020
97ebec3
minimize diff
smoothdeveloper Jan 23, 2020
61478c2
link to usage example in same file
smoothdeveloper Jan 24, 2020
304f505
revert converting CallerArg single cased DU into Record
smoothdeveloper Jan 29, 2020
4352bad
minimize diff
smoothdeveloper Jan 29, 2020
f18a205
minimize diff
smoothdeveloper Jan 29, 2020
7cf610d
minimize diff
smoothdeveloper Jan 29, 2020
5eff584
fix rebase glitches
smoothdeveloper Feb 15, 2020
0d99fef
fix rebase glitch
smoothdeveloper Feb 15, 2020
95fe837
update baseline
smoothdeveloper Feb 15, 2020
4141681
fix base lines / new tests base lines
smoothdeveloper Feb 15, 2020
3042bda
edge case: needs a new line after "A unique overload for method '%s' …
smoothdeveloper Feb 15, 2020
e03f680
updating base line for edge case of missing new line
smoothdeveloper Feb 15, 2020
1b0530d
missing baseline
smoothdeveloper Feb 15, 2020
9ab9ea9
removing comment
smoothdeveloper Feb 18, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DEVGUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Building is simple:

Desktop tests can be run with:

build.cmd -test
build.cmd -test -c Release

After you build the first time you can open and use this solution in Visual Studio:

Expand Down
20 changes: 13 additions & 7 deletions TESTGUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@

To run tests, use variations such as the following, depending on which test suite and build configuration you want:

build.cmd test
build.cmd net40 test
build.cmd coreclr test
build.cmd vs test
build.cmd all test
.\build -testAll -c Release
.\build -test -c Release
.\build -testCambridge -c Release
.\build -testCompiler -c Release
.\build -testDependencyManager -c Release
.\build -testDesktop -c Release
.\build -testCoreClr -c Release
.\build -testFSharpCore -c Release
.\build -testFSharpQA -c Release
.\build -testScripting -c Release
.\build -testVs -c Release

You can also submit pull requests to https://github.com/dotnet/fsharp and run the tests via continuous integration. Most people do wholesale testing that way.

Expand Down Expand Up @@ -48,7 +54,7 @@ There are also negative tests checking code expected to fail compilation. See no

The FSharpQA suite relies on [Perl](http://www.perl.org/get.html), StrawberryPerl package from nuget is used automatically by the test suite.

These tests use the `RunAll.pl` framework to execute, however the easiest way to run them is via the `build.cmd` script, see [usage examples](https://github.com/Microsoft/visualfsharp/blob/master/build.cmd#L31).
These tests use the `RunAll.pl` framework to execute, however the easiest way to run them is via the `.\build` script, see [usage examples](#quick-start-running-tests).

Tests are grouped in folders per area. Each folder contains a number of source code files and a single `env.lst` file. The `env.lst` file defines a series of test cases, one per line.

Expand All @@ -66,7 +72,7 @@ For the FSharpQA suite, the list of test areas and their associated "tags" is st

Tags are in the left column, paths to to corresponding test folders are in the right column. If no tags are specified, all tests will be run.

If you want to re-run a particular test area, the easiest way to do so is to set a temporary tag for that area in test.lst (e.g. "RERUN") and then pass that as an argument to `build.cmd`: `build.cmd test-net40-fsharpqa include RERUN`.
If you want to re-run a particular test area, the easiest way to do so is to set a temporary tag for that area in test.lst (e.g. "RERUN") and adjust `ttags` [run.fsharpqa.test.fsx script](tests/fsharpqa/run.fsharpqa.test.fsx) and run it.

### FSharp.Compiler.UnitTests, FSharp.Core.UnitTests, VisualFSharp.UnitTests

Expand Down
105 changes: 90 additions & 15 deletions src/fsharp/CompileOps.fs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ let GetRangeOfDiagnostic(err: PhasedDiagnostic) =
| NameClash(_, _, _, m, _, _, _)
| UnresolvedOverloading(_, _, _, m)
| UnresolvedConversionOperator (_, _, _, m)
| PossibleOverload(_, _, _, m)
| VirtualAugmentationOnNullValuedType m
| NonVirtualAugmentationOnNullValuedType m
| NonRigidTypar(_, _, _, _, _, m)
Expand Down Expand Up @@ -403,12 +402,9 @@ let warningOn err level specificWarnOn =
| 3180 -> false // abImplicitHeapAllocation - off by default
| _ -> level >= GetWarningLevel err

let SplitRelatedDiagnostics(err: PhasedDiagnostic) =
let SplitRelatedDiagnostics(err: PhasedDiagnostic) : PhasedDiagnostic * PhasedDiagnostic list =
let ToPhased e = {Exception=e; Phase = err.Phase}
let rec SplitRelatedException = function
| UnresolvedOverloading(a, overloads, b, c) ->
let related = overloads |> List.map ToPhased
UnresolvedOverloading(a, [], b, c)|>ToPhased, related
| ConstraintSolverRelatedInformation(fopt, m2, e) ->
let e, related = SplitRelatedException e
ConstraintSolverRelatedInformation(fopt, m2, e.Exception)|>ToPhased, related
Expand Down Expand Up @@ -452,7 +448,6 @@ let ErrorFromApplyingDefault2E() = DeclareResourceString("ErrorFromApplyingDefau
let ErrorsFromAddingSubsumptionConstraintE() = DeclareResourceString("ErrorsFromAddingSubsumptionConstraint", "%s%s%s")
let UpperCaseIdentifierInPatternE() = DeclareResourceString("UpperCaseIdentifierInPattern", "")
let NotUpperCaseConstructorE() = DeclareResourceString("NotUpperCaseConstructor", "")
let PossibleOverloadE() = DeclareResourceString("PossibleOverload", "%s%s")
let FunctionExpectedE() = DeclareResourceString("FunctionExpected", "")
let BakedInMemberConstraintNameE() = DeclareResourceString("BakedInMemberConstraintName", "%s")
let BadEventTransformationE() = DeclareResourceString("BadEventTransformation", "")
Expand Down Expand Up @@ -770,20 +765,100 @@ let OutputPhasedErrorR (os: StringBuilder) (err: PhasedDiagnostic) (canSuggestNa
os.Append(e.ContextualErrorMessage) |> ignore
#endif

| UnresolvedOverloading(_, _, mtext, _) ->
os.Append mtext |> ignore
| UnresolvedOverloading(denv, callerArgs, failure, m) ->

// extract eventual information (return type and type parameters)
// from ConstraintTraitInfo
let knownReturnType, genericParameterTypes =
match failure with
| NoOverloadsFound (cx=Some cx)
| PossibleCandidates (cx=Some cx) -> cx.ReturnType, cx.ArgumentTypes
| _ -> None, []

// prepare message parts (known arguments, known return type, known generic parameters)
let argsMessage, returnType, genericParametersMessage =

let retTy =
knownReturnType
|> Option.defaultValue (TType.TType_var (Typar.NewUnlinked()))

let argRepr =
callerArgs.ArgumentNamesAndTypes
|> List.map (fun (name,tTy) -> tTy, {ArgReprInfo.Name = name |> Option.map (fun name -> Ident(name, range.Zero)); ArgReprInfo.Attribs = []})

let argsL,retTyL,genParamTysL = NicePrint.prettyLayoutsOfUnresolvedOverloading denv argRepr retTy genericParameterTypes

match callerArgs.ArgumentNamesAndTypes with
| [] -> None, Layout.showL retTyL, Layout.showL genParamTysL
| items ->
let args = Layout.showL argsL
let prefixMessage =
match items with
| [_] -> FSComp.SR.csNoOverloadsFoundArgumentsPrefixSingular
| _ -> FSComp.SR.csNoOverloadsFoundArgumentsPrefixPlural
Some (prefixMessage args)
, Layout.showL retTyL
, Layout.showL genParamTysL

let knownReturnType =
match knownReturnType with
| None -> None
| Some _ -> Some (FSComp.SR.csNoOverloadsFoundReturnType returnType)

let genericParametersMessage =
match genericParameterTypes with
| [] -> None
| [_] -> Some (FSComp.SR.csNoOverloadsFoundTypeParametersPrefixSingular genericParametersMessage)
| _ -> Some (FSComp.SR.csNoOverloadsFoundTypeParametersPrefixPlural genericParametersMessage)

let overloadMethodInfo displayEnv m (x: OverloadInformation) =
let paramInfo =
match x.error with
| :? ArgDoesNotMatchError as x ->
let nameOrOneBasedIndexMessage =
x.calledArg.NameOpt
|> Option.map (fun n -> FSComp.SR.csOverloadCandidateNamedArgumentTypeMismatch n.idText)
|> Option.defaultValue (FSComp.SR.csOverloadCandidateIndexedArgumentTypeMismatch ((snd x.calledArg.Position) + 1))
sprintf " // %s" nameOrOneBasedIndexMessage
| _ -> ""

(NicePrint.stringOfMethInfo x.amap m displayEnv x.methodSlot.Method) + paramInfo

let nl = System.Environment.NewLine
let formatOverloads (overloads: OverloadInformation list) =
overloads
|> List.map (overloadMethodInfo denv m)
|> List.sort
|> List.map FSComp.SR.formatDashItem
|> String.concat nl

// assemble final message composing the parts
let msg =
let optionalParts =
[knownReturnType; genericParametersMessage; argsMessage]
|> List.choose id
|> String.concat (nl + nl)
|> function | "" -> nl
| result -> nl + nl + result + nl + nl

match failure with
| NoOverloadsFound (methodName, overloads, _) ->
FSComp.SR.csNoOverloadsFound methodName
+ optionalParts
+ (FSComp.SR.csAvailableOverloads (formatOverloads overloads))
| PossibleCandidates (methodName, [], _) ->
FSComp.SR.csMethodIsOverloaded methodName
| PossibleCandidates (methodName, overloads, _) ->
FSComp.SR.csMethodIsOverloaded methodName
+ optionalParts
+ FSComp.SR.csCandidates (formatOverloads overloads)

os.Append msg |> ignore

| UnresolvedConversionOperator(denv, fromTy, toTy, _) ->
let t1, t2, _tpcs = NicePrint.minimalStringsOfTwoTypes denv fromTy toTy
os.Append(FSComp.SR.csTypeDoesNotSupportConversion(t1, t2)) |> ignore

| PossibleOverload(_, minfo, originalError, _) ->
// print original error that describes reason why this overload was rejected
let buf = new StringBuilder()
OutputExceptionR buf originalError

os.Append(PossibleOverloadE().Format minfo (buf.ToString())) |> ignore

| FunctionExpected _ ->
os.Append(FunctionExpectedE().Format) |> ignore

Expand Down
Loading