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

Better error reporting for record expressions (#15846)

* Better error reporting for duplicated field on record expressions

* WIP

* Update error message

* Update tests

* In copy-and-update we need to reverse the list to get the correct order of fields.

* make it work with copy update syntax and more tests

* Renaming for clarity
上级 47cc8d57
......@@ -1796,6 +1796,12 @@ let FreshenAbstractSlot g amap m synTyparDecls absMethInfo =
let retTyFromAbsSlot = retTy |> GetFSharpViewOfReturnType g |> instType typarInstFromAbsSlot
typarsFromAbsSlotAreRigid, typarsFromAbsSlot, argTysFromAbsSlot, retTyFromAbsSlot
let CheckRecdExprDuplicateFields (elems: Ident list) =
elems |> List.iteri (fun i (uc1: Ident) ->
elems |> List.iteri (fun j (uc2: Ident) ->
if j > i && uc1.idText = uc2.idText then
errorR (Error(FSComp.SR.tcMultipleFieldsInRecord(uc1.idText), uc1.idRange))))
//-------------------------------------------------------------------------
// Helpers to typecheck expressions and patterns
//-------------------------------------------------------------------------
......@@ -1807,9 +1813,14 @@ let BuildFieldMap (cenv: cenv) env isPartial ty (flds: ((Ident list * Ident) * '
if isNil flds then invalidArg "flds" "BuildFieldMap"
let fldCount = flds.Length
let allFields = flds |> List.map (fun ((_, ident), _) -> ident)
if allFields.Length > 1 then
// In the case of nested record fields on the same level in record copy-and-update.
// We need to reverse the list to get the correct order of fields.
let idents = if isPartial then allFields |> List.rev else allFields
CheckRecdExprDuplicateFields idents
let fldResolutions =
let allFields = flds |> List.map (fun ((_, ident), _) -> ident)
flds
|> List.choose (fun (fld, fldExpr) ->
try
......@@ -1838,7 +1849,7 @@ let BuildFieldMap (cenv: cenv) env isPartial ty (flds: ((Ident list * Ident) * '
warning (Error(FSComp.SR.tcFieldsDoNotDetermineUniqueRecordType(), m))
// try finding a record type with the same number of fields as the ones that are given.
match tcrefs |> List.tryFind (fun (_, tc) -> tc.TrueFieldsAsList.Length = fldCount) with
match tcrefs |> List.tryFind (fun (_, tc) -> tc.TrueFieldsAsList.Length = flds.Length) with
| Some (tinst, tcref) -> tinst, tcref
| _ ->
// OK, there isn't a unique, good type dictated by the intersection for the field refs.
......@@ -1863,8 +1874,6 @@ let BuildFieldMap (cenv: cenv) env isPartial ty (flds: ((Ident list * Ident) * '
CheckFSharpAttributes g fref2.PropertyAttribs ident.idRange |> CommitOperationResult
if Map.containsKey fref2.FieldName fs then
errorR (Error(FSComp.SR.tcFieldAppearsTwiceInRecord(fref2.FieldName), m))
if showDeprecated then
let diagnostic = Deprecated(FSComp.SR.nrRecordTypeNeedsQualifiedAccess(fref2.FieldName, fref2.Tycon.DisplayName) |> snd, m)
if g.langVersion.SupportsFeature(LanguageFeature.ErrorOnDeprecatedRequireQualifiedAccess) then
......
......@@ -441,7 +441,7 @@ and TcPatArrayOrList warnOnUpper cenv env vFlags patEnv ty isArray args m =
and TcRecordPat warnOnUpper cenv env vFlags patEnv ty fieldPats m =
let fieldPats = fieldPats |> List.map (fun (fieldId, _, fieldPat) -> fieldId, fieldPat)
match BuildFieldMap cenv env true ty fieldPats m with
match BuildFieldMap cenv env false ty fieldPats m with
| None -> (fun _ -> TPat_error m), patEnv
| Some(tinst, tcref, fldsmap, _fldsList) ->
......
......@@ -520,7 +520,7 @@ tcExpectModuleOrNamespaceParent,"Expected module or namespace parent %s"
665,tcExplicitTypeParameterInvalid,"Explicit type parameters may only be used on module or member bindings"
666,tcOverridingMethodRequiresAllOrNoTypeParameters,"You must explicitly declare either all or no type parameters when overriding a generic abstract method"
667,tcFieldsDoNotDetermineUniqueRecordType,"The field labels and expected type of this record expression or pattern do not uniquely determine a corresponding record type"
668,tcFieldAppearsTwiceInRecord,"The field '%s' appears twice in this record expression or pattern"
668,tcMultipleFieldsInRecord,"The field '%s' appears multiple times in this record expression or pattern"
669,tcUnknownUnion,"Unknown union case"
670,tcNotSufficientlyGenericBecauseOfScope,"This code is not sufficiently generic. The type variable %s could not be generalized because it would escape its scope."
671,tcPropertyRequiresExplicitTypeParameters,"A property cannot have explicit type parameters. Consider using a method instead."
......
......@@ -1227,6 +1227,11 @@
<target state="translated">Je třeba inicializovat následující požadované vlastnosti:{0}</target>
<note />
</trans-unit>
<trans-unit id="tcMultipleFieldsInRecord">
<source>The field '{0}' appears multiple times in this record expression or pattern</source>
<target state="new">The field '{0}' appears multiple times in this record expression or pattern</target>
<note />
</trans-unit>
<trans-unit id="tcMultipleRecdTypeChoice">
<source>Multiple type matches were found:\n{0}\nThe type '{1}' was used. Due to the overlapping field names\n{2}\nconsider using type annotations or change the order of open statements.</source>
<target state="new">Multiple type matches were found:\n{0}\nThe type '{1}' was used. Due to the overlapping field names\n{2}\nconsider using type annotations or change the order of open statements.</target>
......@@ -3882,11 +3887,6 @@
<target state="translated">Tyto popisky pole a očekávaný typ tohoto výrazu záznamu nebo vzoru neurčují jednoznačně odpovídající typ záznamu.</target>
<note />
</trans-unit>
<trans-unit id="tcFieldAppearsTwiceInRecord">
<source>The field '{0}' appears twice in this record expression or pattern</source>
<target state="translated">Pole {0} se v tomto výrazu záznamu nebo vzoru vyskytuje dvakrát.</target>
<note />
</trans-unit>
<trans-unit id="tcUnknownUnion">
<source>Unknown union case</source>
<target state="translated">Neznámý případ typu union</target>
......
......@@ -1227,6 +1227,11 @@
<target state="translated">Die folgenden erforderlichen Eigenschaften müssen initialisiert werden:{0}</target>
<note />
</trans-unit>
<trans-unit id="tcMultipleFieldsInRecord">
<source>The field '{0}' appears multiple times in this record expression or pattern</source>
<target state="new">The field '{0}' appears multiple times in this record expression or pattern</target>
<note />
</trans-unit>
<trans-unit id="tcMultipleRecdTypeChoice">
<source>Multiple type matches were found:\n{0}\nThe type '{1}' was used. Due to the overlapping field names\n{2}\nconsider using type annotations or change the order of open statements.</source>
<target state="new">Multiple type matches were found:\n{0}\nThe type '{1}' was used. Due to the overlapping field names\n{2}\nconsider using type annotations or change the order of open statements.</target>
......@@ -3882,11 +3887,6 @@
<target state="translated">Anhand der Feldbezeichnungen und des erwarteten Typs dieses Datensatzausdrucks oder Musters lässt sich kein eindeutiger Datensatztyp bestimmen.</target>
<note />
</trans-unit>
<trans-unit id="tcFieldAppearsTwiceInRecord">
<source>The field '{0}' appears twice in this record expression or pattern</source>
<target state="translated">Das Feld "{0}" ist in diesem Datensatzausdruck oder Muster zweimal vorhanden.</target>
<note />
</trans-unit>
<trans-unit id="tcUnknownUnion">
<source>Unknown union case</source>
<target state="translated">Unbekannter Union-Fall.</target>
......
......@@ -1227,6 +1227,11 @@
<target state="translated">Se deben inicializar las siguientes propiedades necesarias:{0}</target>
<note />
</trans-unit>
<trans-unit id="tcMultipleFieldsInRecord">
<source>The field '{0}' appears multiple times in this record expression or pattern</source>
<target state="new">The field '{0}' appears multiple times in this record expression or pattern</target>
<note />
</trans-unit>
<trans-unit id="tcMultipleRecdTypeChoice">
<source>Multiple type matches were found:\n{0}\nThe type '{1}' was used. Due to the overlapping field names\n{2}\nconsider using type annotations or change the order of open statements.</source>
<target state="new">Multiple type matches were found:\n{0}\nThe type '{1}' was used. Due to the overlapping field names\n{2}\nconsider using type annotations or change the order of open statements.</target>
......@@ -3882,11 +3887,6 @@
<target state="translated">Las etiquetas de campo y el tipo esperado de este patrón o expresión de registro no determinan de forma única un tipo de registro correspondiente.</target>
<note />
</trans-unit>
<trans-unit id="tcFieldAppearsTwiceInRecord">
<source>The field '{0}' appears twice in this record expression or pattern</source>
<target state="translated">El campo '{0}' aparece dos veces en este patrón o expresión de registro.</target>
<note />
</trans-unit>
<trans-unit id="tcUnknownUnion">
<source>Unknown union case</source>
<target state="translated">Caso de unión desconocido.</target>
......
......@@ -1227,6 +1227,11 @@
<target state="translated">Les propriétés requises suivantes doivent être initialisées :{0}</target>
<note />
</trans-unit>
<trans-unit id="tcMultipleFieldsInRecord">
<source>The field '{0}' appears multiple times in this record expression or pattern</source>
<target state="new">The field '{0}' appears multiple times in this record expression or pattern</target>
<note />
</trans-unit>
<trans-unit id="tcMultipleRecdTypeChoice">
<source>Multiple type matches were found:\n{0}\nThe type '{1}' was used. Due to the overlapping field names\n{2}\nconsider using type annotations or change the order of open statements.</source>
<target state="new">Multiple type matches were found:\n{0}\nThe type '{1}' was used. Due to the overlapping field names\n{2}\nconsider using type annotations or change the order of open statements.</target>
......@@ -3882,11 +3887,6 @@
<target state="translated">Les étiquettes et le type attendu du champ de cette expression d'enregistrement ou ce modèle d'enregistrement ne déterminent pas de manière unique un type enregistrement correspondant</target>
<note />
</trans-unit>
<trans-unit id="tcFieldAppearsTwiceInRecord">
<source>The field '{0}' appears twice in this record expression or pattern</source>
<target state="translated">Le champ '{0}' apparaît à deux reprises dans cette expression ou ce modèle d'enregistrement</target>
<note />
</trans-unit>
<trans-unit id="tcUnknownUnion">
<source>Unknown union case</source>
<target state="translated">Cas d'union inconnu</target>
......
......@@ -1227,6 +1227,11 @@
<target state="translated">È necessario inizializzare le proprietà obbligatorie seguenti:{0}</target>
<note />
</trans-unit>
<trans-unit id="tcMultipleFieldsInRecord">
<source>The field '{0}' appears multiple times in this record expression or pattern</source>
<target state="new">The field '{0}' appears multiple times in this record expression or pattern</target>
<note />
</trans-unit>
<trans-unit id="tcMultipleRecdTypeChoice">
<source>Multiple type matches were found:\n{0}\nThe type '{1}' was used. Due to the overlapping field names\n{2}\nconsider using type annotations or change the order of open statements.</source>
<target state="new">Multiple type matches were found:\n{0}\nThe type '{1}' was used. Due to the overlapping field names\n{2}\nconsider using type annotations or change the order of open statements.</target>
......@@ -3882,11 +3887,6 @@
<target state="translated">Le etichette di campo e il tipo previsto di questo criterio o espressione del record non determinano in modo univoco un tipo di record corrispondente</target>
<note />
</trans-unit>
<trans-unit id="tcFieldAppearsTwiceInRecord">
<source>The field '{0}' appears twice in this record expression or pattern</source>
<target state="translated">Il campo '{0}' è presente due volte nei criteri o nell'espressione del record</target>
<note />
</trans-unit>
<trans-unit id="tcUnknownUnion">
<source>Unknown union case</source>
<target state="translated">Case di unione sconosciuto</target>
......
......@@ -1227,6 +1227,11 @@
<target state="translated">次の必須プロパティを初期化する必要があります:{0}</target>
<note />
</trans-unit>
<trans-unit id="tcMultipleFieldsInRecord">
<source>The field '{0}' appears multiple times in this record expression or pattern</source>
<target state="new">The field '{0}' appears multiple times in this record expression or pattern</target>
<note />
</trans-unit>
<trans-unit id="tcMultipleRecdTypeChoice">
<source>Multiple type matches were found:\n{0}\nThe type '{1}' was used. Due to the overlapping field names\n{2}\nconsider using type annotations or change the order of open statements.</source>
<target state="new">Multiple type matches were found:\n{0}\nThe type '{1}' was used. Due to the overlapping field names\n{2}\nconsider using type annotations or change the order of open statements.</target>
......@@ -3882,11 +3887,6 @@
<target state="translated">フィールド ラベルとこのレコード式またはパターンの型だけでは、対応するレコード型を一意に決定できません</target>
<note />
</trans-unit>
<trans-unit id="tcFieldAppearsTwiceInRecord">
<source>The field '{0}' appears twice in this record expression or pattern</source>
<target state="translated">のレコード式またはパターンに、フィールド '{0}' が 2 回出現します</target>
<note />
</trans-unit>
<trans-unit id="tcUnknownUnion">
<source>Unknown union case</source>
<target state="translated">不明な共用体ケースです</target>
......
......@@ -1227,6 +1227,11 @@
<target state="translated">다음 필수 속성을 초기화해야 합니다. {0}</target>
<note />
</trans-unit>
<trans-unit id="tcMultipleFieldsInRecord">
<source>The field '{0}' appears multiple times in this record expression or pattern</source>
<target state="new">The field '{0}' appears multiple times in this record expression or pattern</target>
<note />
</trans-unit>
<trans-unit id="tcMultipleRecdTypeChoice">
<source>Multiple type matches were found:\n{0}\nThe type '{1}' was used. Due to the overlapping field names\n{2}\nconsider using type annotations or change the order of open statements.</source>
<target state="new">Multiple type matches were found:\n{0}\nThe type '{1}' was used. Due to the overlapping field names\n{2}\nconsider using type annotations or change the order of open statements.</target>
......@@ -3882,11 +3887,6 @@
<target state="translated">이 레코드 식 또는 패턴의 필요한 형식 및 필드 레이블이 해당하는 레코드 형식을 고유하게 확인하지 않습니다.</target>
<note />
</trans-unit>
<trans-unit id="tcFieldAppearsTwiceInRecord">
<source>The field '{0}' appears twice in this record expression or pattern</source>
<target state="translated">'{0}' 필드가 이 레코드 식 또는 패턴에 두 번 나타납니다.</target>
<note />
</trans-unit>
<trans-unit id="tcUnknownUnion">
<source>Unknown union case</source>
<target state="translated">알 수 없는 공용 구조체 케이스입니다.</target>
......
......@@ -1227,6 +1227,11 @@
<target state="translated">Następujące wymagane właściwości muszą zostać zainicjowane:{0}</target>
<note />
</trans-unit>
<trans-unit id="tcMultipleFieldsInRecord">
<source>The field '{0}' appears multiple times in this record expression or pattern</source>
<target state="new">The field '{0}' appears multiple times in this record expression or pattern</target>
<note />
</trans-unit>
<trans-unit id="tcMultipleRecdTypeChoice">
<source>Multiple type matches were found:\n{0}\nThe type '{1}' was used. Due to the overlapping field names\n{2}\nconsider using type annotations or change the order of open statements.</source>
<target state="new">Multiple type matches were found:\n{0}\nThe type '{1}' was used. Due to the overlapping field names\n{2}\nconsider using type annotations or change the order of open statements.</target>
......@@ -3882,11 +3887,6 @@
<target state="translated">Etykiety pól i oczekiwany typ tego wyrażenia rekordu lub wzorca nie określają jednoznacznie odpowiedniego typu rekordu</target>
<note />
</trans-unit>
<trans-unit id="tcFieldAppearsTwiceInRecord">
<source>The field '{0}' appears twice in this record expression or pattern</source>
<target state="translated">Pole „{0}” występuje dwa razy w tym wyrażeniu rekordu lub wzorcu</target>
<note />
</trans-unit>
<trans-unit id="tcUnknownUnion">
<source>Unknown union case</source>
<target state="translated">Nieznany przypadek unii</target>
......
......@@ -1227,6 +1227,11 @@
<target state="translated">As seguintes propriedades necessárias precisam ser inicializadas:{0}</target>
<note />
</trans-unit>
<trans-unit id="tcMultipleFieldsInRecord">
<source>The field '{0}' appears multiple times in this record expression or pattern</source>
<target state="new">The field '{0}' appears multiple times in this record expression or pattern</target>
<note />
</trans-unit>
<trans-unit id="tcMultipleRecdTypeChoice">
<source>Multiple type matches were found:\n{0}\nThe type '{1}' was used. Due to the overlapping field names\n{2}\nconsider using type annotations or change the order of open statements.</source>
<target state="new">Multiple type matches were found:\n{0}\nThe type '{1}' was used. Due to the overlapping field names\n{2}\nconsider using type annotations or change the order of open statements.</target>
......@@ -3882,11 +3887,6 @@
<target state="translated">Os rótulos de campo e tipo esperado desta expressão ou padrão de registro não determinam exclusivamente um tipo de registro correspondente</target>
<note />
</trans-unit>
<trans-unit id="tcFieldAppearsTwiceInRecord">
<source>The field '{0}' appears twice in this record expression or pattern</source>
<target state="translated">O campo '{0}' aparece duas vezes nesta expressão de registro ou padrão</target>
<note />
</trans-unit>
<trans-unit id="tcUnknownUnion">
<source>Unknown union case</source>
<target state="translated">Caso união desconhecido</target>
......
......@@ -1227,6 +1227,11 @@
<target state="translated">Необходимо инициализировать следующие обязательные свойства:{0}</target>
<note />
</trans-unit>
<trans-unit id="tcMultipleFieldsInRecord">
<source>The field '{0}' appears multiple times in this record expression or pattern</source>
<target state="new">The field '{0}' appears multiple times in this record expression or pattern</target>
<note />
</trans-unit>
<trans-unit id="tcMultipleRecdTypeChoice">
<source>Multiple type matches were found:\n{0}\nThe type '{1}' was used. Due to the overlapping field names\n{2}\nconsider using type annotations or change the order of open statements.</source>
<target state="new">Multiple type matches were found:\n{0}\nThe type '{1}' was used. Due to the overlapping field names\n{2}\nconsider using type annotations or change the order of open statements.</target>
......@@ -3882,11 +3887,6 @@
<target state="translated">Метки поля и требуемый тип данного выражения записи или шаблона не определяют уникально соответствующий тип записи</target>
<note />
</trans-unit>
<trans-unit id="tcFieldAppearsTwiceInRecord">
<source>The field '{0}' appears twice in this record expression or pattern</source>
<target state="translated">Поле "{0}" появляется дважды в данном выражении записи или шаблоне</target>
<note />
</trans-unit>
<trans-unit id="tcUnknownUnion">
<source>Unknown union case</source>
<target state="translated">Неизвестная ветвь объединения</target>
......
......@@ -1227,6 +1227,11 @@
<target state="translated">Aşağıdaki gerekli özelliklerin başlatılması gerekiyor:{0}</target>
<note />
</trans-unit>
<trans-unit id="tcMultipleFieldsInRecord">
<source>The field '{0}' appears multiple times in this record expression or pattern</source>
<target state="new">The field '{0}' appears multiple times in this record expression or pattern</target>
<note />
</trans-unit>
<trans-unit id="tcMultipleRecdTypeChoice">
<source>Multiple type matches were found:\n{0}\nThe type '{1}' was used. Due to the overlapping field names\n{2}\nconsider using type annotations or change the order of open statements.</source>
<target state="new">Multiple type matches were found:\n{0}\nThe type '{1}' was used. Due to the overlapping field names\n{2}\nconsider using type annotations or change the order of open statements.</target>
......@@ -3882,11 +3887,6 @@
<target state="translated">Bu kayıt ifadesinin veya deseninin alan etiketleri ve beklenen türü, karşılık gelen bir kayıt türünü benzersiz olarak belirlemiyor</target>
<note />
</trans-unit>
<trans-unit id="tcFieldAppearsTwiceInRecord">
<source>The field '{0}' appears twice in this record expression or pattern</source>
<target state="translated">'{0}' alanı bu kayıt ifadesinde veya deseninde iki kez görünüyor</target>
<note />
</trans-unit>
<trans-unit id="tcUnknownUnion">
<source>Unknown union case</source>
<target state="translated">Bilinmeyen birleşim durumu</target>
......
......@@ -1227,6 +1227,11 @@
<target state="translated">必须初始化以下必需属性: {0}</target>
<note />
</trans-unit>
<trans-unit id="tcMultipleFieldsInRecord">
<source>The field '{0}' appears multiple times in this record expression or pattern</source>
<target state="new">The field '{0}' appears multiple times in this record expression or pattern</target>
<note />
</trans-unit>
<trans-unit id="tcMultipleRecdTypeChoice">
<source>Multiple type matches were found:\n{0}\nThe type '{1}' was used. Due to the overlapping field names\n{2}\nconsider using type annotations or change the order of open statements.</source>
<target state="new">Multiple type matches were found:\n{0}\nThe type '{1}' was used. Due to the overlapping field names\n{2}\nconsider using type annotations or change the order of open statements.</target>
......@@ -3882,11 +3887,6 @@
<target state="translated">此记录表达式或模式的字段标签和预期类型没有唯一确定相应的记录类型</target>
<note />
</trans-unit>
<trans-unit id="tcFieldAppearsTwiceInRecord">
<source>The field '{0}' appears twice in this record expression or pattern</source>
<target state="translated">字段“{0}”在此记录表达式或模式中出现了两次</target>
<note />
</trans-unit>
<trans-unit id="tcUnknownUnion">
<source>Unknown union case</source>
<target state="translated">未知的联合用例</target>
......
......@@ -1227,6 +1227,11 @@
<target state="translated">下列必要的屬性必須初始化:{0}</target>
<note />
</trans-unit>
<trans-unit id="tcMultipleFieldsInRecord">
<source>The field '{0}' appears multiple times in this record expression or pattern</source>
<target state="new">The field '{0}' appears multiple times in this record expression or pattern</target>
<note />
</trans-unit>
<trans-unit id="tcMultipleRecdTypeChoice">
<source>Multiple type matches were found:\n{0}\nThe type '{1}' was used. Due to the overlapping field names\n{2}\nconsider using type annotations or change the order of open statements.</source>
<target state="new">Multiple type matches were found:\n{0}\nThe type '{1}' was used. Due to the overlapping field names\n{2}\nconsider using type annotations or change the order of open statements.</target>
......@@ -3882,11 +3887,6 @@
<target state="translated">這個記錄運算式或模式的欄位標籤和預期類型無法唯一決定對應的記錄類型</target>
<note />
</trans-unit>
<trans-unit id="tcFieldAppearsTwiceInRecord">
<source>The field '{0}' appears twice in this record expression or pattern</source>
<target state="translated">欄位 '{0}' 在這個記錄運算式或模式中出現兩次</target>
<note />
</trans-unit>
<trans-unit id="tcUnknownUnion">
<source>Unknown union case</source>
<target state="translated">未知的聯集</target>
......
......@@ -381,3 +381,165 @@ module RecordTypes =
|> withDiagnostics [
(Warning 864, Line 11, Col 22, Line 11, Col 30, "This new member hides the abstract member 'System.Object.ToString() : string'. Rename the member or use 'override' instead.")
]
[<Fact>]
let ``Records field appears multiple times in this record expressions``() =
FSharp """
type RecTy = { B: string }
let t1 = { B = "a"; B = "b" }
"""
|> typecheck
|> shouldFail
|> withDiagnostics [
(Error 668, Line 4, Col 16, Line 4, Col 17, "The field 'B' appears multiple times in this record expression or pattern")
]
[<Fact>]
let ``Records field appears multiple times in this record expressions 2``() =
FSharp """
type RecTy = { B: string }
let t1 = { B = "a"; B = "b"; B = "c" }
"""
|> typecheck
|> shouldFail
|> withDiagnostics [
(Error 668, Line 4, Col 16, Line 4, Col 17, "The field 'B' appears multiple times in this record expression or pattern")
(Error 668, Line 4, Col 25, Line 4, Col 26, "The field 'B' appears multiple times in this record expression or pattern")
]
[<Fact>]
let ``Records field appears multiple times in this record expressions 3``() =
FSharp """
type RecTy = { A: int; B: int }
let t1 = { A = 1; B = 4; A = 5; B = 4 }
"""
|> typecheck
|> shouldFail
|> withDiagnostics [
(Error 668, Line 4, Col 16, Line 4, Col 17, "The field 'A' appears multiple times in this record expression or pattern")
(Error 668, Line 4, Col 23, Line 4, Col 24, "The field 'B' appears multiple times in this record expression or pattern")
]
[<Fact>]
let ``Records field appears multiple times in this record expressions 4``() =
FSharp """
type RecTy = { A: int; B: int; C: string }
let t1 = { A = 1; C = ""; A = 0; B = 5 }
"""
|> typecheck
|> shouldFail
|> withDiagnostics [
(Error 668, Line 4, Col 16, Line 4, Col 17, "The field 'A' appears multiple times in this record expression or pattern")
]
[<Fact>]
let ``Records field appears multiple times in this record expressions 5``() =
FSharp """
type RecTy = { A: int; B: int; C: string }
let t1 = { A = 4; C = ""; A = 8; B = 4; A = 9 }
"""
|> typecheck
|> shouldFail
|> withDiagnostics [
(Error 668, Line 4, Col 16, Line 4, Col 17, "The field 'A' appears multiple times in this record expression or pattern")
(Error 668, Line 4, Col 31, Line 4, Col 32, "The field 'A' appears multiple times in this record expression or pattern")
]
[<Fact>]
let ``Records field appears multiple times in this record expressions 6``() =
FSharp """
type RecTy = { ``A``: int; B: int; C: string }
let t1 = { ``A`` = 5; B = 6; A = 6; B = 6; C = "" }
"""
|> typecheck
|> shouldFail
|> withDiagnostics [
(Error 668, Line 4, Col 16, Line 4, Col 21, "The field 'A' appears multiple times in this record expression or pattern")
(Error 668, Line 4, Col 27, Line 4, Col 28, "The field 'B' appears multiple times in this record expression or pattern")
]
[<Fact>]
let ``Records field appears multiple times in this record expressions 7``() =
FSharp """
type RecTy = { A: int; B: int; C: string }
let t1 = { A = 5; B = 6; C = "" }
match t1 with
| { A = 5; A = 6; C = "" } -> ()
| _ -> ()
"""
|> typecheck
|> shouldFail
|> withDiagnostics [
(Error 668, Line 5, Col 9, Line 5, Col 10, "The field 'A' appears multiple times in this record expression or pattern")
]
[<Fact>]
let ``Records field appears multiple times in this record expressions 8``() =
FSharp """
type RecTy = { A: int; B: int; C: string }
let t1 = { A = 5; B = 6; C = "" }
match t1 with
| { A = 5; A = 6; A = 8 } -> ()
| _ -> ()
"""
|> typecheck
|> shouldFail
|> withDiagnostics [
(Error 668, Line 5, Col 9, Line 5, Col 10, "The field 'A' appears multiple times in this record expression or pattern")
(Error 668, Line 5, Col 16, Line 5, Col 17, "The field 'A' appears multiple times in this record expression or pattern")
]
[<Fact>]
let ``Records field appears multiple times in this record expressions 9``() =
FSharp """
type RecTy = { A: int; B: int; C: string }
let t1 = { A = 5; B = 6; C = "" }
match t1 with
| { A = 5; B = 6; A = 8; B = 9; C = "" } -> ()
| _ -> ()
"""
|> typecheck
|> shouldFail
|> withDiagnostics [
(Error 668, Line 5, Col 9, Line 5, Col 10, "The field 'A' appears multiple times in this record expression or pattern")
(Error 668, Line 5, Col 16, Line 5, Col 17, "The field 'B' appears multiple times in this record expression or pattern")
]
[<Fact>]
let ``Records field appears multiple times in this record expressions 10``() =
FSharp """
type RecTy = { A: int; B: int; C: string }
let t1 = { A = 5; B = 6; C = "" }
match t1 with
| { A = 4; C = ""; A = 8; B = 4; A = 9 } -> ()
| _ -> ()
"""
|> typecheck
|> shouldFail
|> withDiagnostics [
(Error 668, Line 5, Col 9, Line 5, Col 10, "The field 'A' appears multiple times in this record expression or pattern")
(Error 668, Line 5, Col 24, Line 5, Col 25, "The field 'A' appears multiple times in this record expression or pattern")
]
[<Fact>]
let ``Records field appears multiple times in this record expressions 11``() =
FSharp """
type RecTy = { A: int; B: int; C: string }
let t1 = { A = 5; B = 6; C = "" }
match t1 with
| { A = 4; C = ""; A = 8; B = 4; A = 9; B = 4 } -> ()
| _ -> ()
"""
|> typecheck
|> shouldFail
|> withDiagnostics [
(Error 668, Line 5, Col 9, Line 5, Col 10, "The field 'A' appears multiple times in this record expression or pattern")
(Error 668, Line 5, Col 24, Line 5, Col 25, "The field 'A' appears multiple times in this record expression or pattern")
(Error 668, Line 5, Col 31, Line 5, Col 32, "The field 'B' appears multiple times in this record expression or pattern")
]
\ No newline at end of file
......@@ -17,7 +17,41 @@ let t2 x = { x with D.B = "a"; D.B = "b" }
|> typecheck
|> shouldFail
|> withDiagnostics [
(Error 668, Line 6, Col 21, Line 6, Col 22, "The field 'B' appears twice in this record expression or pattern")
(Error 668, Line 6, Col 23, Line 6, Col 24, "The field 'B' appears multiple times in this record expression or pattern")
]
[<Fact>]
let ``Cannot update the same field appears multiple times in nested copy-and-update``() =
FSharp """
type NestdRecTy = { B: string }
type RecTy = { D: NestdRecTy; E: string option }
let t2 x = { x with D.B = "a"; D.B = "b"; D.B = "c" }
"""
|> withLangVersionPreview
|> typecheck
|> shouldFail
|> withDiagnostics [
(Error 668, Line 6, Col 23, Line 6, Col 24, "The field 'B' appears multiple times in this record expression or pattern")
(Error 668, Line 6, Col 34, Line 6, Col 35, "The field 'B' appears multiple times in this record expression or pattern")
]
[<Fact>]
let ``Cannot update the same field appears multiple times in nested copy-and-update 2``() =
FSharp """
type NestdRecTy = { B: string; C: string }
type RecTy = { D: NestdRecTy; E: string option }
let t2 x = { x with D.B = "a"; D.C = ""; D.B = "c" ; D.C = "d" }
"""
|> withLangVersionPreview
|> typecheck
|> shouldFail
|> withDiagnostics [
(Error 668, Line 6, Col 34, Line 6, Col 35, "The field 'C' appears multiple times in this record expression or pattern")
(Error 668, Line 6, Col 23, Line 6, Col 24, "The field 'B' appears multiple times in this record expression or pattern")
]
[<Fact>]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册