未验证 提交 ea04308f 编写于 作者: E Edgar Gonzalez 提交者: GitHub

Improve Unclear error FS3204 Multicase union struct (#14105)

* Improve Unclear error FS3204 multicase union case struct
上级 1617a15e
......@@ -3164,8 +3164,16 @@ module EstablishTypeDefinitionCores =
if not ctorArgNames.IsEmpty then errorR (Error(FSComp.SR.parsOnlyClassCanTakeValueArguments(), m))
let envinner = AddDeclaredTypars CheckForDuplicateTypars (tycon.Typars m) envinner
let envinner = MakeInnerEnvForTyconRef envinner thisTyconRef false
let envinner = MakeInnerEnvForTyconRef envinner thisTyconRef false
let multiCaseUnionStructCheck (unionCases: UnionCase list) =
if tycon.IsStructRecordOrUnionTycon && unionCases.Length > 1 then
let fieldNames = [ for uc in unionCases do for ft in uc.FieldTable.TrueInstanceFieldsAsList do yield (ft.LogicalName, ft.Range) ]
let distFieldNames = fieldNames |> List.distinctBy fst
if distFieldNames.Length <> fieldNames.Length then
let fieldRanges = distFieldNames |> List.map snd
for m in fieldRanges do
errorR(Error(FSComp.SR.tcStructUnionMultiCaseDistinctFields(), m))
// Notify the Language Service about field names in record/class declaration
let ad = envinner.AccessRights
......@@ -3257,10 +3265,7 @@ module EstablishTypeDefinitionCores =
let hasRQAAttribute = HasFSharpAttribute cenv.g cenv.g.attrib_RequireQualifiedAccessAttribute tycon.Attribs
let unionCases = TcRecdUnionAndEnumDeclarations.TcUnionCaseDecls cenv envinner innerParent thisTy thisTyInst hasRQAAttribute tpenv unionCases
if tycon.IsStructRecordOrUnionTycon && unionCases.Length > 1 then
let fieldNames = [ for uc in unionCases do for ft in uc.FieldTable.TrueInstanceFieldsAsList do yield ft.LogicalName ]
if fieldNames |> List.distinct |> List.length <> fieldNames.Length then
errorR(Error(FSComp.SR.tcStructUnionMultiCaseDistinctFields(), m))
multiCaseUnionStructCheck unionCases
writeFakeUnionCtorsToSink unionCases
let repr = Construct.MakeUnionRepr unionCases
......
......@@ -1372,7 +1372,7 @@ tcTupleStructMismatch,"One tuple type is a struct tuple, the other is a referenc
3201,tcModuleAbbrevFirstInMutRec,"In a recursive declaration group, module abbreviations must come after all 'open' declarations and before other declarations"
3202,tcUnsupportedMutRecDecl,"This declaration is not supported in recursive declaration groups"
3203,parsInvalidUseOfRec,"Invalid use of 'rec' keyword"
3204,tcStructUnionMultiCaseDistinctFields,"If a union type has more than one case and is a struct, then all fields within the union type must be given unique names."
3204,tcStructUnionMultiCaseDistinctFields,"If a multicase union type is a struct, then all union cases must have unique names. For example: 'type A = B of b: int | C of c: int'."
3206,CallerMemberNameIsOverriden,"The CallerMemberNameAttribute applied to parameter '%s' will have no effect. It is overridden by the CallerFilePathAttribute."
3207,tcFixedNotAllowed,"Invalid use of 'fixed'. 'fixed' may only be used in a declaration of the form 'use x = fixed expr' where the expression is an array, the address of a field, the address of an array element or a string'"
3208,tcCouldNotFindOffsetToStringData,"Could not find method System.Runtime.CompilerServices.OffsetToStringData in references when building 'fixed' expression."
......
......@@ -7513,8 +7513,8 @@
<note />
</trans-unit>
<trans-unit id="tcStructUnionMultiCaseDistinctFields">
<source>If a union type has more than one case and is a struct, then all fields within the union type must be given unique names.</source>
<target state="translated">Pokud je typ sjednocení struktura a obsahuje více než jeden případ, všem polím v tomto typu sjednocení se musí přiřadit jedinečný název.</target>
<source>If a multicase union type is a struct, then all union cases must have unique names. For example: 'type A = B of b: int | C of c: int'.</source>
<target state="needs-review-translation">Pokud je typ sjednocení struktura a obsahuje více než jeden případ, všem polím v tomto typu sjednocení se musí přiřadit jedinečný název.</target>
<note />
</trans-unit>
<trans-unit id="CallerMemberNameIsOverriden">
......
......@@ -7513,8 +7513,8 @@
<note />
</trans-unit>
<trans-unit id="tcStructUnionMultiCaseDistinctFields">
<source>If a union type has more than one case and is a struct, then all fields within the union type must be given unique names.</source>
<target state="translated">Wenn ein Union-Typ mehrere case-Anweisungen aufweist und eine Struktur ist, müssen für alle Felder im Union-Typ eindeutige Namen angegeben werden.</target>
<source>If a multicase union type is a struct, then all union cases must have unique names. For example: 'type A = B of b: int | C of c: int'.</source>
<target state="needs-review-translation">Wenn ein Union-Typ mehrere case-Anweisungen aufweist und eine Struktur ist, müssen für alle Felder im Union-Typ eindeutige Namen angegeben werden.</target>
<note />
</trans-unit>
<trans-unit id="CallerMemberNameIsOverriden">
......
......@@ -7513,8 +7513,8 @@
<note />
</trans-unit>
<trans-unit id="tcStructUnionMultiCaseDistinctFields">
<source>If a union type has more than one case and is a struct, then all fields within the union type must be given unique names.</source>
<target state="translated">Si un tipo de unión tiene más de un caso y un struct, a todos los campos dentro del tipo de unión se les deben dar nombres únicos.</target>
<source>If a multicase union type is a struct, then all union cases must have unique names. For example: 'type A = B of b: int | C of c: int'.</source>
<target state="needs-review-translation">Si un tipo de unión tiene más de un caso y un struct, a todos los campos dentro del tipo de unión se les deben dar nombres únicos.</target>
<note />
</trans-unit>
<trans-unit id="CallerMemberNameIsOverriden">
......
......@@ -7513,8 +7513,8 @@
<note />
</trans-unit>
<trans-unit id="tcStructUnionMultiCaseDistinctFields">
<source>If a union type has more than one case and is a struct, then all fields within the union type must be given unique names.</source>
<target state="translated">Si un type union a plusieurs étiquettes case, et s'il s'agit d'un struct, tous les champs du type union doivent avoir des noms uniques.</target>
<source>If a multicase union type is a struct, then all union cases must have unique names. For example: 'type A = B of b: int | C of c: int'.</source>
<target state="needs-review-translation">Si un type union a plusieurs étiquettes case, et s'il s'agit d'un struct, tous les champs du type union doivent avoir des noms uniques.</target>
<note />
</trans-unit>
<trans-unit id="CallerMemberNameIsOverriden">
......
......@@ -7513,8 +7513,8 @@
<note />
</trans-unit>
<trans-unit id="tcStructUnionMultiCaseDistinctFields">
<source>If a union type has more than one case and is a struct, then all fields within the union type must be given unique names.</source>
<target state="translated">Se un tipo di unione contiene più di un case ed è una struttura, è necessario assegnare nomi univoci a tutti i campi all'interno del tipo di unione.</target>
<source>If a multicase union type is a struct, then all union cases must have unique names. For example: 'type A = B of b: int | C of c: int'.</source>
<target state="needs-review-translation">Se un tipo di unione contiene più di un case ed è una struttura, è necessario assegnare nomi univoci a tutti i campi all'interno del tipo di unione.</target>
<note />
</trans-unit>
<trans-unit id="CallerMemberNameIsOverriden">
......
......@@ -7513,8 +7513,8 @@
<note />
</trans-unit>
<trans-unit id="tcStructUnionMultiCaseDistinctFields">
<source>If a union type has more than one case and is a struct, then all fields within the union type must be given unique names.</source>
<target state="translated">共用体型が複数のケースを持つ 1 つの構造体である場合は、共用体型内のすべてのフィールドに一意の名前を付ける必要があります。</target>
<source>If a multicase union type is a struct, then all union cases must have unique names. For example: 'type A = B of b: int | C of c: int'.</source>
<target state="needs-review-translation">共用体型が複数のケースを持つ 1 つの構造体である場合は、共用体型内のすべてのフィールドに一意の名前を付ける必要があります。</target>
<note />
</trans-unit>
<trans-unit id="CallerMemberNameIsOverriden">
......
......@@ -7513,8 +7513,8 @@
<note />
</trans-unit>
<trans-unit id="tcStructUnionMultiCaseDistinctFields">
<source>If a union type has more than one case and is a struct, then all fields within the union type must be given unique names.</source>
<target state="translated">공용 구조체 형식이 둘 이상의 case를 포함하고 구조체인 경우 공용 구조체 형식 내의 모든 필드에 고유한 이름을 지정해야 합니다.</target>
<source>If a multicase union type is a struct, then all union cases must have unique names. For example: 'type A = B of b: int | C of c: int'.</source>
<target state="needs-review-translation">공용 구조체 형식이 둘 이상의 case를 포함하고 구조체인 경우 공용 구조체 형식 내의 모든 필드에 고유한 이름을 지정해야 합니다.</target>
<note />
</trans-unit>
<trans-unit id="CallerMemberNameIsOverriden">
......
......@@ -7513,8 +7513,8 @@
<note />
</trans-unit>
<trans-unit id="tcStructUnionMultiCaseDistinctFields">
<source>If a union type has more than one case and is a struct, then all fields within the union type must be given unique names.</source>
<target state="translated">Jeśli typ unii ma więcej niż jeden przypadek i jest strukturą, wszystkim polom w typie unii należy nadać unikatowe nazwy.</target>
<source>If a multicase union type is a struct, then all union cases must have unique names. For example: 'type A = B of b: int | C of c: int'.</source>
<target state="needs-review-translation">Jeśli typ unii ma więcej niż jeden przypadek i jest strukturą, wszystkim polom w typie unii należy nadać unikatowe nazwy.</target>
<note />
</trans-unit>
<trans-unit id="CallerMemberNameIsOverriden">
......
......@@ -7513,8 +7513,8 @@
<note />
</trans-unit>
<trans-unit id="tcStructUnionMultiCaseDistinctFields">
<source>If a union type has more than one case and is a struct, then all fields within the union type must be given unique names.</source>
<target state="translated">Se um tipo de união tiver mais de um caso e for struct, então todos os campos dentro do tipo de união deverão ter nomes exclusivos.</target>
<source>If a multicase union type is a struct, then all union cases must have unique names. For example: 'type A = B of b: int | C of c: int'.</source>
<target state="needs-review-translation">Se um tipo de união tiver mais de um caso e for struct, então todos os campos dentro do tipo de união deverão ter nomes exclusivos.</target>
<note />
</trans-unit>
<trans-unit id="CallerMemberNameIsOverriden">
......
......@@ -7513,8 +7513,8 @@
<note />
</trans-unit>
<trans-unit id="tcStructUnionMultiCaseDistinctFields">
<source>If a union type has more than one case and is a struct, then all fields within the union type must be given unique names.</source>
<target state="translated">Если тип объединения имеет более одного варианта и является структурой, всем полям в типе объединения необходимо присвоить уникальные имена.</target>
<source>If a multicase union type is a struct, then all union cases must have unique names. For example: 'type A = B of b: int | C of c: int'.</source>
<target state="needs-review-translation">Если тип объединения имеет более одного варианта и является структурой, всем полям в типе объединения необходимо присвоить уникальные имена.</target>
<note />
</trans-unit>
<trans-unit id="CallerMemberNameIsOverriden">
......
......@@ -7513,8 +7513,8 @@
<note />
</trans-unit>
<trans-unit id="tcStructUnionMultiCaseDistinctFields">
<source>If a union type has more than one case and is a struct, then all fields within the union type must be given unique names.</source>
<target state="translated">Bir birleşim türü büyük ve küçük harfler içeriyorsa ve bir yapıysa, birleşim türü içindeki tüm alanlara benzersiz adlar verilmelidir.</target>
<source>If a multicase union type is a struct, then all union cases must have unique names. For example: 'type A = B of b: int | C of c: int'.</source>
<target state="needs-review-translation">Bir birleşim türü büyük ve küçük harfler içeriyorsa ve bir yapıysa, birleşim türü içindeki tüm alanlara benzersiz adlar verilmelidir.</target>
<note />
</trans-unit>
<trans-unit id="CallerMemberNameIsOverriden">
......
......@@ -7513,8 +7513,8 @@
<note />
</trans-unit>
<trans-unit id="tcStructUnionMultiCaseDistinctFields">
<source>If a union type has more than one case and is a struct, then all fields within the union type must be given unique names.</source>
<target state="translated">如果联合类型有多个用例且为结构,则必须赋予此联合类型中的所有字段唯一的名称。</target>
<source>If a multicase union type is a struct, then all union cases must have unique names. For example: 'type A = B of b: int | C of c: int'.</source>
<target state="needs-review-translation">如果联合类型有多个用例且为结构,则必须赋予此联合类型中的所有字段唯一的名称。</target>
<note />
</trans-unit>
<trans-unit id="CallerMemberNameIsOverriden">
......
......@@ -7513,8 +7513,8 @@
<note />
</trans-unit>
<trans-unit id="tcStructUnionMultiCaseDistinctFields">
<source>If a union type has more than one case and is a struct, then all fields within the union type must be given unique names.</source>
<target state="translated">如果等位型別有一個以上的案例並且為結構,等位型別內所有欄位的名稱就都不得重複。</target>
<source>If a multicase union type is a struct, then all union cases must have unique names. For example: 'type A = B of b: int | C of c: int'.</source>
<target state="needs-review-translation">如果等位型別有一個以上的案例並且為結構,等位型別內所有欄位的名稱就都不得重複。</target>
<note />
</trans-unit>
<trans-unit id="CallerMemberNameIsOverriden">
......
......@@ -94,6 +94,7 @@
<Compile Include="Conformance\TypesAndTypeConstraints\LogicalPropertiesOfTypes\LogicalPropertiesOfTypes.fs" />
<Compile Include="Conformance\TypesAndTypeConstraints\IWSAMsAndSRTPs\IWSAMsAndSRTPsTests.fs" />
<Compile Include="Conformance\UnionTypes\UnionTypes.fs" />
<Compile Include="Conformance\UnionTypes\MultiCaseUnionStructTypes.fs" />
<Compile Include="Conformance\UnitsOfMeasure\Basic.fs" />
<Compile Include="Conformance\UnitsOfMeasure\Diagnostics.fs" />
<Compile Include="Conformance\UnitsOfMeasure\Parsing.fs" />
......
......@@ -80,7 +80,6 @@ namespace FSharpTest
"""
|> compile
|> shouldSucceed
|> ignore
[<Fact>]
let ``CheckingSyntacticTypes - TcTyconDefnCore_CheckForCyclicStructsAndInheritance - Non-Struct DU Tree Cyclic Tree`` () =
......
......@@ -13,10 +13,4 @@ neg95.fs(39,7,39,18): typecheck error FS3200: In a recursive declaration group,
neg95.fs(45,10,45,22): typecheck error FS0954: This type definition involves an immediate cyclic reference through a struct field or inheritance relation
neg95.fs(52,10,52,21): typecheck error FS0954: This type definition involves an immediate cyclic reference through a struct field or inheritance relation
neg95.fs(55,10,55,22): typecheck error FS3204: If a union type has more than one case and is a struct, then all fields within the union type must be given unique names.
neg95.fs(58,10,58,22): typecheck error FS3204: If a union type has more than one case and is a struct, then all fields within the union type must be given unique names.
neg95.fs(61,10,61,22): typecheck error FS0954: This type definition involves an immediate cyclic reference through a struct field or inheritance relation
neg95.fs(52,10,52,21): typecheck error FS0954: This type definition involves an immediate cyclic reference through a struct field or inheritance relation
\ No newline at end of file
......@@ -50,12 +50,3 @@ namespace Neg95B
[<Struct>]
type StructUnion = StructUnion of float * StructUnion
[<Struct>]
type StructUnion2 = A of int | B of string
[<Struct>]
type StructUnion3 = A of X:int | B of X:string
[<Struct>]
type StructUnion4 = A of X:int | B of Y:StructUnion4
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册