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

Better error message when using wrong anon record #15732

Merged
merged 6 commits into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
26 changes: 24 additions & 2 deletions src/Compiler/Checking/ConstraintSolver.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1078,7 +1078,9 @@ and SolveAnonInfoEqualsAnonInfo (csenv: ConstraintSolverEnv) m2 (anonInfo1: Anon
elif Set.intersect first second <> Set.empty then
Overlap(firstOnly, secondOnly)
else
CompletelyDifferent(Seq.toList first)
let first = Set.toList first
let second = Set.toList second
CompletelyDifferent(first, second)

let message =
match anonInfo1.SortedNames, anonInfo2.SortedNames with
Expand All @@ -1087,19 +1089,39 @@ and SolveAnonInfoEqualsAnonInfo (csenv: ConstraintSolverEnv) m2 (anonInfo1: Anon
| [missingField] ->
FSComp.SR.tcAnonRecdSingleFieldNameSubset(string missingField)
| _ ->
let missingFields = missingFields |> List.map(sprintf "'%s'")
let missingFields = String.concat ", " missingFields
FSComp.SR.tcAnonRecdMultipleFieldsNameSubset(string missingFields)
| Superset extraFields ->
match extraFields with
| [extraField] ->
FSComp.SR.tcAnonRecdSingleFieldNameSuperset(string extraField)
| _ ->
let extraFields = extraFields |> List.map(sprintf "'%s'")
let extraFields = String.concat ", " extraFields
FSComp.SR.tcAnonRecdMultipleFieldsNameSuperset(string extraFields)
| Overlap (missingFields, extraFields) ->
FSComp.SR.tcAnonRecdFieldNameMismatch(string missingFields, string extraFields)
| CompletelyDifferent missingFields ->
FSComp.SR.tcAnonRecdFieldNameDifferent(string missingFields)
let missingFields, usedFields = missingFields
match missingFields, usedFields with
| [ missingField ], [ usedField ] ->
FSComp.SR.tcAnonRecdSingleFieldNameSingleDifferent(missingField, usedField)
| [ missingField ], usedFields ->
let usedFields = usedFields |> List.map(sprintf "'%s'")
let usedFields = String.concat ", " usedFields
FSComp.SR.tcAnonRecdSingleFieldNameMultipleDifferent(missingField, usedFields)
| missingFields, [ usedField ] ->
let missingFields = missingFields |> List.map(sprintf "'%s'")
let missingFields = String.concat ", " missingFields
FSComp.SR.tcAnonRecdMultipleFieldNameSingleDifferent(missingFields, usedField)

| missingFields, usedFields ->
let missingFields = missingFields |> List.map(sprintf "'%s'")
let missingFields = String.concat ", " missingFields
let usedFields = usedFields |> List.map(sprintf "'%s'")
let usedFields = String.concat ", " usedFields
FSComp.SR.tcAnonRecdMultipleFieldNameMultipleDifferent(missingFields, usedFields)

ErrorD (ConstraintSolverError(message, csenv.m,m2))
else
Expand Down
9 changes: 6 additions & 3 deletions src/Compiler/FSComp.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1396,10 +1396,13 @@ tcAnonRecdInvalid,"Invalid Anonymous Record type declaration."
tcAnonRecdCcuMismatch,"Two anonymous record types are from different assemblies '%s' and '%s'"
tcAnonRecdFieldNameMismatch,"This anonymous record does not exactly match the expected shape. Add the missing fields %s and remove the extra fields %s."
tcAnonRecdSingleFieldNameSubset,"This anonymous record is missing field '%s'."
tcAnonRecdMultipleFieldsNameSubset,"This anonymous record is missing fields '%s'."
tcAnonRecdMultipleFieldsNameSubset,"This anonymous record is missing fields %s."
tcAnonRecdSingleFieldNameSuperset,"This anonymous record has an extra field. Remove field '%s'."
tcAnonRecdMultipleFieldsNameSuperset,"This anonymous record has extra fields. Remove fields '%s'."
tcAnonRecdFieldNameDifferent,"This is the wrong anonymous record. It should have the fields %s."
tcAnonRecdMultipleFieldsNameSuperset,"This anonymous record has extra fields. Remove fields %s."
tcAnonRecdSingleFieldNameSingleDifferent,"This anonymous record should have field '%s' but here has field '%s'."
tcAnonRecdSingleFieldNameMultipleDifferent,"This anonymous record should have field '%s' but here has fields %s."
tcAnonRecdMultipleFieldNameSingleDifferent,"This anonymous record should have fields %s; but here has field '%s'."
tcAnonRecdMultipleFieldNameMultipleDifferent,"This anonymous record should have fields %s; but here has fields %s."
keywordDescriptionAbstract,"Indicates a method that either has no implementation in the type in which it is declared or that is virtual and has a default implementation."
keywordDescriptionAnd,"Used in mutually recursive bindings, in property declarations, and with multiple constraints on generic parameters."
keywordDescriptionAs,"Used to give the current class object an object name. Also used to give a name to a whole pattern within a pattern match."
Expand Down
39 changes: 27 additions & 12 deletions src/Compiler/xlf/FSComp.txt.cs.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 27 additions & 12 deletions src/Compiler/xlf/FSComp.txt.de.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 27 additions & 12 deletions src/Compiler/xlf/FSComp.txt.es.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading