Skip to content

Commit d508baf

Browse files
authored
Better error message for-anon records with extra fields (#15719)
1 parent 2580bfd commit d508baf

File tree

16 files changed

+160
-67
lines changed

16 files changed

+160
-67
lines changed

src/Compiler/Checking/ConstraintSolver.fs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1090,7 +1090,12 @@ and SolveAnonInfoEqualsAnonInfo (csenv: ConstraintSolverEnv) m2 (anonInfo1: Anon
10901090
let missingFields = String.concat ", " missingFields
10911091
FSComp.SR.tcAnonRecdMultipleFieldsNameSubset(string missingFields)
10921092
| Superset extraFields ->
1093-
FSComp.SR.tcAnonRecdFieldNameSuperset(string extraFields)
1093+
match extraFields with
1094+
| [extraField] ->
1095+
FSComp.SR.tcAnonRecdSingleFieldNameSuperset(string extraField)
1096+
| _ ->
1097+
let extraFields = String.concat ", " extraFields
1098+
FSComp.SR.tcAnonRecdMultipleFieldsNameSuperset(string extraFields)
10941099
| Overlap (missingFields, extraFields) ->
10951100
FSComp.SR.tcAnonRecdFieldNameMismatch(string missingFields, string extraFields)
10961101
| CompletelyDifferent missingFields ->

src/Compiler/FSComp.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1397,7 +1397,8 @@ tcAnonRecdCcuMismatch,"Two anonymous record types are from different assemblies
13971397
tcAnonRecdFieldNameMismatch,"This anonymous record does not exactly match the expected shape. Add the missing fields %s and remove the extra fields %s."
13981398
tcAnonRecdSingleFieldNameSubset,"This anonymous record is missing field '%s'."
13991399
tcAnonRecdMultipleFieldsNameSubset,"This anonymous record is missing fields '%s'."
1400-
tcAnonRecdFieldNameSuperset,"This anonymous record has too many fields. Remove the extra fields %s."
1400+
tcAnonRecdSingleFieldNameSuperset,"This anonymous record has an extra field. Remove field '%s'."
1401+
tcAnonRecdMultipleFieldsNameSuperset,"This anonymous record has extra fields. Remove fields '%s'."
14011402
tcAnonRecdFieldNameDifferent,"This is the wrong anonymous record. It should have the fields %s."
14021403
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."
14031404
keywordDescriptionAnd,"Used in mutually recursive bindings, in property declarations, and with multiple constraints on generic parameters."

src/Compiler/xlf/FSComp.txt.cs.xlf

Lines changed: 10 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compiler/xlf/FSComp.txt.de.xlf

Lines changed: 10 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compiler/xlf/FSComp.txt.es.xlf

Lines changed: 10 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compiler/xlf/FSComp.txt.fr.xlf

Lines changed: 10 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compiler/xlf/FSComp.txt.it.xlf

Lines changed: 10 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compiler/xlf/FSComp.txt.ja.xlf

Lines changed: 10 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compiler/xlf/FSComp.txt.ko.xlf

Lines changed: 10 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compiler/xlf/FSComp.txt.pl.xlf

Lines changed: 10 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)