Skip to content
This repository was archived by the owner on Dec 23, 2024. It is now read-only.

Commit 6978b05

Browse files
isaacabrahamnosami
authored andcommitted
Better anonymous record reporting (dotnet#8094)
* Initial attempt at better anonymous record reporting. * Update error texts and fix tests. * Fix test, but for real this time. * Fix another random BSL file. * Next random file fix! * Line formatting.
1 parent 42bc601 commit 6978b05

18 files changed

+260
-37
lines changed

src/fsharp/ConstraintSolver.fs

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -835,10 +835,35 @@ and SolveAnonInfoEqualsAnonInfo (csenv: ConstraintSolverEnv) m2 (anonInfo1: Anon
835835
(match anonInfo1.Assembly, anonInfo2.Assembly with
836836
| ccu1, ccu2 -> if not (ccuEq ccu1 ccu2) then ErrorD (ConstraintSolverError(FSComp.SR.tcAnonRecdCcuMismatch(ccu1.AssemblyName, ccu2.AssemblyName), csenv.m,m2)) else ResultD ()
837837
) ++ (fun () ->
838+
838839
if not (anonInfo1.SortedNames = anonInfo2.SortedNames) then
839-
let namesText1 = sprintf "%A" (Array.toList anonInfo1.SortedNames)
840-
let namesText2 = sprintf "%A" (Array.toList anonInfo2.SortedNames)
841-
ErrorD (ConstraintSolverError(FSComp.SR.tcAnonRecdFieldNameMismatch(namesText1, namesText2), csenv.m,m2))
840+
let (|Subset|Superset|Overlap|CompletelyDifferent|) (first, second) =
841+
let first = Set first
842+
let second = Set second
843+
let secondOnly = Set.toList (second - first)
844+
let firstOnly = Set.toList (first - second)
845+
846+
if second.IsSubsetOf first then
847+
Subset firstOnly
848+
elif second.IsSupersetOf first then
849+
Superset secondOnly
850+
elif Set.intersect first second <> Set.empty then
851+
Overlap(firstOnly, secondOnly)
852+
else
853+
CompletelyDifferent(Seq.toList first)
854+
855+
let message =
856+
match anonInfo1.SortedNames, anonInfo2.SortedNames with
857+
| Subset missingFields ->
858+
FSComp.SR.tcAnonRecdFieldNameSubset(string missingFields)
859+
| Superset extraFields ->
860+
FSComp.SR.tcAnonRecdFieldNameSuperset(string extraFields)
861+
| Overlap (missingFields, extraFields) ->
862+
FSComp.SR.tcAnonRecdFieldNameMismatch(string missingFields, string extraFields)
863+
| CompletelyDifferent missingFields ->
864+
FSComp.SR.tcAnonRecdFieldNameDifferent(string missingFields)
865+
866+
ErrorD (ConstraintSolverError(message, csenv.m,m2))
842867
else
843868
ResultD ())
844869

src/fsharp/FSComp.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1350,7 +1350,10 @@ tcGlobalsSystemTypeNotFound,"The system type '%s' was required but no referenced
13501350
3214,methodIsNotStatic,"Method or object constructor '%s' is not static"
13511351
3215,parsUnexpectedSymbolEqualsInsteadOfIn,"Unexpected symbol '=' in expression. Did you intend to use 'for x in y .. z do' instead?"
13521352
tcAnonRecdCcuMismatch,"Two anonymous record types are from different assemblies '%s' and '%s'"
1353-
tcAnonRecdFieldNameMismatch,"Two anonymous record types have mismatched sets of field names '%s' and '%s'"
1353+
tcAnonRecdFieldNameMismatch,"This anonymous record does not exactly match the expected shape. Add the missing fields %s and remove the extra fields %s."
1354+
tcAnonRecdFieldNameSubset,"This anonymous record does not have enough fields. Add the missing fields %s."
1355+
tcAnonRecdFieldNameSuperset,"This anonymous record has too many fields. Remove the extra fields %s."
1356+
tcAnonRecdFieldNameDifferent,"This is the wrong anonymous record. It should have the fields %s."
13541357
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."
13551358
keyworkDescriptionAnd,"Used in mutually recursive bindings, in property declarations, and with multiple constraints on generic parameters."
13561359
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."

src/fsharp/xlf/FSComp.txt.cs.xlf

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,21 @@
2727
<target state="new">Algorithm '{0}' is not supported</target>
2828
<note />
2929
</trans-unit>
30+
<trans-unit id="tcAnonRecdFieldNameDifferent">
31+
<source>This is the wrong anonymous record. It should have the fields {0}.</source>
32+
<target state="new">This is the wrong anonymous record. It should have the fields {0}.</target>
33+
<note />
34+
</trans-unit>
35+
<trans-unit id="tcAnonRecdFieldNameSubset">
36+
<source>This anonymous record does not have enough fields. Add the missing fields {0}.</source>
37+
<target state="new">This anonymous record does not have enough fields. Add the missing fields {0}.</target>
38+
<note />
39+
</trans-unit>
40+
<trans-unit id="tcAnonRecdFieldNameSuperset">
41+
<source>This anonymous record has too many fields. Remove the extra fields {0}.</source>
42+
<target state="new">This anonymous record has too many fields. Remove the extra fields {0}.</target>
43+
<note />
44+
</trans-unit>
3045
<trans-unit id="tcAugmentationsCannotHaveAttributes">
3146
<source>Attributes cannot be applied to type extensions.</source>
3247
<target state="translated">Atributy nejde použít pro rozšíření typů.</target>
@@ -7108,8 +7123,8 @@
71087123
<note />
71097124
</trans-unit>
71107125
<trans-unit id="tcAnonRecdFieldNameMismatch">
7111-
<source>Two anonymous record types have mismatched sets of field names '{0}' and '{1}'</source>
7112-
<target state="translated">Dva typy anonymních záznamů mají odlišné sady názvů polí: {0} a {1}</target>
7126+
<source>This anonymous record does not exactly match the expected shape. Add the missing fields {0} and remove the extra fields {1}.</source>
7127+
<target state="needs-review-translation">Dva typy anonymních záznamů mají odlišné sady názvů polí: {0} a {1}</target>
71137128
<note />
71147129
</trans-unit>
71157130
<trans-unit id="tcCannotCallExtensionMethodInrefToByref">

src/fsharp/xlf/FSComp.txt.de.xlf

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,21 @@
2727
<target state="new">Algorithm '{0}' is not supported</target>
2828
<note />
2929
</trans-unit>
30+
<trans-unit id="tcAnonRecdFieldNameDifferent">
31+
<source>This is the wrong anonymous record. It should have the fields {0}.</source>
32+
<target state="new">This is the wrong anonymous record. It should have the fields {0}.</target>
33+
<note />
34+
</trans-unit>
35+
<trans-unit id="tcAnonRecdFieldNameSubset">
36+
<source>This anonymous record does not have enough fields. Add the missing fields {0}.</source>
37+
<target state="new">This anonymous record does not have enough fields. Add the missing fields {0}.</target>
38+
<note />
39+
</trans-unit>
40+
<trans-unit id="tcAnonRecdFieldNameSuperset">
41+
<source>This anonymous record has too many fields. Remove the extra fields {0}.</source>
42+
<target state="new">This anonymous record has too many fields. Remove the extra fields {0}.</target>
43+
<note />
44+
</trans-unit>
3045
<trans-unit id="tcAugmentationsCannotHaveAttributes">
3146
<source>Attributes cannot be applied to type extensions.</source>
3247
<target state="translated">Attribute können nicht auf Typerweiterungen angewendet werden.</target>
@@ -7108,8 +7123,8 @@
71087123
<note />
71097124
</trans-unit>
71107125
<trans-unit id="tcAnonRecdFieldNameMismatch">
7111-
<source>Two anonymous record types have mismatched sets of field names '{0}' and '{1}'</source>
7112-
<target state="translated">Zwei anonyme Datensatztypen weisen die nicht übereinstimmenden Feldnamen "{0}" und "{1}" auf.</target>
7126+
<source>This anonymous record does not exactly match the expected shape. Add the missing fields {0} and remove the extra fields {1}.</source>
7127+
<target state="needs-review-translation">Zwei anonyme Datensatztypen weisen die nicht übereinstimmenden Feldnamen "{0}" und "{1}" auf.</target>
71137128
<note />
71147129
</trans-unit>
71157130
<trans-unit id="tcCannotCallExtensionMethodInrefToByref">

src/fsharp/xlf/FSComp.txt.es.xlf

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,21 @@
2727
<target state="new">Algorithm '{0}' is not supported</target>
2828
<note />
2929
</trans-unit>
30+
<trans-unit id="tcAnonRecdFieldNameDifferent">
31+
<source>This is the wrong anonymous record. It should have the fields {0}.</source>
32+
<target state="new">This is the wrong anonymous record. It should have the fields {0}.</target>
33+
<note />
34+
</trans-unit>
35+
<trans-unit id="tcAnonRecdFieldNameSubset">
36+
<source>This anonymous record does not have enough fields. Add the missing fields {0}.</source>
37+
<target state="new">This anonymous record does not have enough fields. Add the missing fields {0}.</target>
38+
<note />
39+
</trans-unit>
40+
<trans-unit id="tcAnonRecdFieldNameSuperset">
41+
<source>This anonymous record has too many fields. Remove the extra fields {0}.</source>
42+
<target state="new">This anonymous record has too many fields. Remove the extra fields {0}.</target>
43+
<note />
44+
</trans-unit>
3045
<trans-unit id="tcAugmentationsCannotHaveAttributes">
3146
<source>Attributes cannot be applied to type extensions.</source>
3247
<target state="translated">Los atributos no se pueden aplicar a las extensiones de tipo.</target>
@@ -139,7 +154,7 @@
139154
</trans-unit>
140155
<trans-unit id="followingPatternMatchClauseHasWrongType">
141156
<source>All branches of a pattern match expression must return values of the same type as the first branch, which here is '{0}'. This branch returns a value of type '{1}'.</source>
142-
<target state="translated">Todas las ramas de una expresión de coincidencia de patrón deben devolver valores del mismo tipo. La primera rama devolvió un valor de tipo "{0}", pero esta rama devolvió un valor de tipo "\{1 \}".</target>
157+
<target state="new">All branches of a pattern match expression must return values of the same type as the first branch, which here is '{0}'. This branch returns a value of type '{1}'.</target>
143158
<note />
144159
</trans-unit>
145160
<trans-unit id="patternMatchGuardIsNotBool">
@@ -7108,8 +7123,8 @@
71087123
<note />
71097124
</trans-unit>
71107125
<trans-unit id="tcAnonRecdFieldNameMismatch">
7111-
<source>Two anonymous record types have mismatched sets of field names '{0}' and '{1}'</source>
7112-
<target state="translated">Dos tipos de registros anónimos tienen conjuntos de nombres de campo que no coinciden "{0}" y "{1}"</target>
7126+
<source>This anonymous record does not exactly match the expected shape. Add the missing fields {0} and remove the extra fields {1}.</source>
7127+
<target state="needs-review-translation">Dos tipos de registros anónimos tienen conjuntos de nombres de campo que no coinciden "{0}" y "{1}"</target>
71137128
<note />
71147129
</trans-unit>
71157130
<trans-unit id="tcCannotCallExtensionMethodInrefToByref">

src/fsharp/xlf/FSComp.txt.fr.xlf

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,21 @@
2727
<target state="new">Algorithm '{0}' is not supported</target>
2828
<note />
2929
</trans-unit>
30+
<trans-unit id="tcAnonRecdFieldNameDifferent">
31+
<source>This is the wrong anonymous record. It should have the fields {0}.</source>
32+
<target state="new">This is the wrong anonymous record. It should have the fields {0}.</target>
33+
<note />
34+
</trans-unit>
35+
<trans-unit id="tcAnonRecdFieldNameSubset">
36+
<source>This anonymous record does not have enough fields. Add the missing fields {0}.</source>
37+
<target state="new">This anonymous record does not have enough fields. Add the missing fields {0}.</target>
38+
<note />
39+
</trans-unit>
40+
<trans-unit id="tcAnonRecdFieldNameSuperset">
41+
<source>This anonymous record has too many fields. Remove the extra fields {0}.</source>
42+
<target state="new">This anonymous record has too many fields. Remove the extra fields {0}.</target>
43+
<note />
44+
</trans-unit>
3045
<trans-unit id="tcAugmentationsCannotHaveAttributes">
3146
<source>Attributes cannot be applied to type extensions.</source>
3247
<target state="translated">Impossible d'appliquer des attributs aux extensions de type.</target>
@@ -7108,8 +7123,8 @@
71087123
<note />
71097124
</trans-unit>
71107125
<trans-unit id="tcAnonRecdFieldNameMismatch">
7111-
<source>Two anonymous record types have mismatched sets of field names '{0}' and '{1}'</source>
7112-
<target state="translated">Deux types d'enregistrement anonyme ont des ensembles de noms de champ incompatibles '{0}' et '{1}'</target>
7126+
<source>This anonymous record does not exactly match the expected shape. Add the missing fields {0} and remove the extra fields {1}.</source>
7127+
<target state="needs-review-translation">Deux types d'enregistrement anonyme ont des ensembles de noms de champ incompatibles '{0}' et '{1}'</target>
71137128
<note />
71147129
</trans-unit>
71157130
<trans-unit id="tcCannotCallExtensionMethodInrefToByref">

src/fsharp/xlf/FSComp.txt.it.xlf

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,21 @@
2727
<target state="new">Algorithm '{0}' is not supported</target>
2828
<note />
2929
</trans-unit>
30+
<trans-unit id="tcAnonRecdFieldNameDifferent">
31+
<source>This is the wrong anonymous record. It should have the fields {0}.</source>
32+
<target state="new">This is the wrong anonymous record. It should have the fields {0}.</target>
33+
<note />
34+
</trans-unit>
35+
<trans-unit id="tcAnonRecdFieldNameSubset">
36+
<source>This anonymous record does not have enough fields. Add the missing fields {0}.</source>
37+
<target state="new">This anonymous record does not have enough fields. Add the missing fields {0}.</target>
38+
<note />
39+
</trans-unit>
40+
<trans-unit id="tcAnonRecdFieldNameSuperset">
41+
<source>This anonymous record has too many fields. Remove the extra fields {0}.</source>
42+
<target state="new">This anonymous record has too many fields. Remove the extra fields {0}.</target>
43+
<note />
44+
</trans-unit>
3045
<trans-unit id="tcAugmentationsCannotHaveAttributes">
3146
<source>Attributes cannot be applied to type extensions.</source>
3247
<target state="translated">Gli attributi non possono essere applicati a estensioni di tipo.</target>
@@ -7108,8 +7123,8 @@
71087123
<note />
71097124
</trans-unit>
71107125
<trans-unit id="tcAnonRecdFieldNameMismatch">
7111-
<source>Two anonymous record types have mismatched sets of field names '{0}' and '{1}'</source>
7112-
<target state="translated">Due tipi di record anonimo contengono set di nomi di campo '{0}' e '{1}' non corrispondenti</target>
7126+
<source>This anonymous record does not exactly match the expected shape. Add the missing fields {0} and remove the extra fields {1}.</source>
7127+
<target state="needs-review-translation">Due tipi di record anonimo contengono set di nomi di campo '{0}' e '{1}' non corrispondenti</target>
71137128
<note />
71147129
</trans-unit>
71157130
<trans-unit id="tcCannotCallExtensionMethodInrefToByref">

src/fsharp/xlf/FSComp.txt.ja.xlf

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,21 @@
4747
<target state="translated">アルゴリズム '{0}' はサポートされていません</target>
4848
<note />
4949
</trans-unit>
50+
<trans-unit id="tcAnonRecdFieldNameDifferent">
51+
<source>This is the wrong anonymous record. It should have the fields {0}.</source>
52+
<target state="new">This is the wrong anonymous record. It should have the fields {0}.</target>
53+
<note />
54+
</trans-unit>
55+
<trans-unit id="tcAnonRecdFieldNameSubset">
56+
<source>This anonymous record does not have enough fields. Add the missing fields {0}.</source>
57+
<target state="new">This anonymous record does not have enough fields. Add the missing fields {0}.</target>
58+
<note />
59+
</trans-unit>
60+
<trans-unit id="tcAnonRecdFieldNameSuperset">
61+
<source>This anonymous record has too many fields. Remove the extra fields {0}.</source>
62+
<target state="new">This anonymous record has too many fields. Remove the extra fields {0}.</target>
63+
<note />
64+
</trans-unit>
5065
<trans-unit id="tcAugmentationsCannotHaveAttributes">
5166
<source>Attributes cannot be applied to type extensions.</source>
5267
<target state="translated">属性を型拡張に適用することはできません。</target>
@@ -7128,8 +7143,8 @@
71287143
<note />
71297144
</trans-unit>
71307145
<trans-unit id="tcAnonRecdFieldNameMismatch">
7131-
<source>Two anonymous record types have mismatched sets of field names '{0}' and '{1}'</source>
7132-
<target state="translated">2 種類の匿名レコードのフィールド名 '{0}' と '{1}' が一致しません</target>
7146+
<source>This anonymous record does not exactly match the expected shape. Add the missing fields {0} and remove the extra fields {1}.</source>
7147+
<target state="needs-review-translation">2 種類の匿名レコードのフィールド名 '{0}' と '{1}' が一致しません</target>
71337148
<note />
71347149
</trans-unit>
71357150
<trans-unit id="tcCannotCallExtensionMethodInrefToByref">

src/fsharp/xlf/FSComp.txt.ko.xlf

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,21 @@
2727
<target state="new">Algorithm '{0}' is not supported</target>
2828
<note />
2929
</trans-unit>
30+
<trans-unit id="tcAnonRecdFieldNameDifferent">
31+
<source>This is the wrong anonymous record. It should have the fields {0}.</source>
32+
<target state="new">This is the wrong anonymous record. It should have the fields {0}.</target>
33+
<note />
34+
</trans-unit>
35+
<trans-unit id="tcAnonRecdFieldNameSubset">
36+
<source>This anonymous record does not have enough fields. Add the missing fields {0}.</source>
37+
<target state="new">This anonymous record does not have enough fields. Add the missing fields {0}.</target>
38+
<note />
39+
</trans-unit>
40+
<trans-unit id="tcAnonRecdFieldNameSuperset">
41+
<source>This anonymous record has too many fields. Remove the extra fields {0}.</source>
42+
<target state="new">This anonymous record has too many fields. Remove the extra fields {0}.</target>
43+
<note />
44+
</trans-unit>
3045
<trans-unit id="tcAugmentationsCannotHaveAttributes">
3146
<source>Attributes cannot be applied to type extensions.</source>
3247
<target state="translated">형식 확장에 특성을 적용할 수 없습니다.</target>
@@ -7108,8 +7123,8 @@
71087123
<note />
71097124
</trans-unit>
71107125
<trans-unit id="tcAnonRecdFieldNameMismatch">
7111-
<source>Two anonymous record types have mismatched sets of field names '{0}' and '{1}'</source>
7112-
<target state="translated">두 무명 레코드 형식의 필드 이름 '{0}' 및 '{1}' 집합이 일치하지 않습니다.</target>
7126+
<source>This anonymous record does not exactly match the expected shape. Add the missing fields {0} and remove the extra fields {1}.</source>
7127+
<target state="needs-review-translation">두 무명 레코드 형식의 필드 이름 '{0}' 및 '{1}' 집합이 일치하지 않습니다.</target>
71137128
<note />
71147129
</trans-unit>
71157130
<trans-unit id="tcCannotCallExtensionMethodInrefToByref">

0 commit comments

Comments
 (0)