From e0574e8128bc1a7fe0b2fb70d8b1a56a7ccab97c Mon Sep 17 00:00:00 2001 From: Gauthier Segay Date: Sat, 30 Dec 2023 13:17:26 +0100 Subject: [PATCH 1/2] suggested message clarifying usage of augmentation attributes for issue 960 --- src/Compiler/Checking/AugmentWithHashCompare.fs | 6 +++++- src/Compiler/FSComp.txt | 1 + src/Compiler/xlf/FSComp.txt.cs.xlf | 5 +++++ src/Compiler/xlf/FSComp.txt.de.xlf | 5 +++++ src/Compiler/xlf/FSComp.txt.es.xlf | 5 +++++ src/Compiler/xlf/FSComp.txt.fr.xlf | 5 +++++ src/Compiler/xlf/FSComp.txt.it.xlf | 5 +++++ src/Compiler/xlf/FSComp.txt.ja.xlf | 5 +++++ src/Compiler/xlf/FSComp.txt.ko.xlf | 5 +++++ src/Compiler/xlf/FSComp.txt.pl.xlf | 5 +++++ src/Compiler/xlf/FSComp.txt.pt-BR.xlf | 5 +++++ src/Compiler/xlf/FSComp.txt.ru.xlf | 5 +++++ src/Compiler/xlf/FSComp.txt.tr.xlf | 5 +++++ src/Compiler/xlf/FSComp.txt.zh-Hans.xlf | 5 +++++ src/Compiler/xlf/FSComp.txt.zh-Hant.xlf | 5 +++++ 15 files changed, 71 insertions(+), 1 deletion(-) diff --git a/src/Compiler/Checking/AugmentWithHashCompare.fs b/src/Compiler/Checking/AugmentWithHashCompare.fs index d3e9fb1d42d..f96bd3104f7 100644 --- a/src/Compiler/Checking/AugmentWithHashCompare.fs +++ b/src/Compiler/Checking/AugmentWithHashCompare.fs @@ -1082,7 +1082,11 @@ let CheckAugmentationAttribs isImplementation g amap (tycon: Tycon) = | false, _, _, _, _, Some true, _, _, _ | false, _, _, _, _, _, _, _, Some true -> errorR (Error(FSComp.SR.augOnlyCertainTypesCanHaveAttrs (), m)) // All other cases - | _ -> errorR (Error(FSComp.SR.augInvalidAttrs (), m)) + | _ -> + if tycon.IsFSharpObjectModelTycon then + errorR (Error(FSComp.SR.augInvalidAttrsForFSharpObjectModelType(), m)) + else + errorR (Error(FSComp.SR.augInvalidAttrs (), m)) let hasNominalInterface tcref = let ty = generalizedTyconRef g (mkLocalTyconRef tycon) diff --git a/src/Compiler/FSComp.txt b/src/Compiler/FSComp.txt index 8df6fecfdfb..1047cdb2c5f 100644 --- a/src/Compiler/FSComp.txt +++ b/src/Compiler/FSComp.txt @@ -227,6 +227,7 @@ astDeprecatedIndexerNotation,"This indexer notation has been removed from the F# 386,augNoEqNeedsNoObjEquals,"A type with attribute 'NoEquality' should not usually have an explicit implementation of 'Object.Equals(obj)'. Disable this warning if this is intentional for interoperability purposes" 386,augNoCompCantImpIComp,"A type with attribute 'NoComparison' should not usually have an explicit implementation of 'System.IComparable', 'System.IComparable<_>' or 'System.Collections.IStructuralComparable'. Disable this warning if this is intentional for interoperability purposes" 387,augCustomEqNeedsNoCompOrCustomComp,"The 'CustomEquality' attribute must be used in conjunction with the 'NoComparison' or 'CustomComparison' attributes" +388,augInvalidAttrsForFSharpObjectModelType,"The attributes 'NoEquality', 'ReferenceEquality', 'StructuralEquality', 'NoComparison' and 'StructuralComparison' aren't meant to be used on adhoc classes, interfaces, structures, enums, delegates but only on discriminated unions or record types." forPositionalSpecifiersNotPermitted,"Positional specifiers are not permitted in format strings" forMissingFormatSpecifier,"Missing format specifier" forFlagSetTwice,"'%s' flag set twice" diff --git a/src/Compiler/xlf/FSComp.txt.cs.xlf b/src/Compiler/xlf/FSComp.txt.cs.xlf index c07ba0d7033..6f9e712c353 100644 --- a/src/Compiler/xlf/FSComp.txt.cs.xlf +++ b/src/Compiler/xlf/FSComp.txt.cs.xlf @@ -12,6 +12,11 @@ Všechny prvky pole musí být implicitně převoditelné na typ prvního elementu, což je řazená kolekce členů o délce {0} typu\n {1} \nTento element je řazená kolekce členů o délce {2} typu\n {3} \n + + The attributes 'NoEquality', 'ReferenceEquality', 'StructuralEquality', 'NoComparison' and 'StructuralComparison' aren't meant to be used on adhoc classes, interfaces, structures, enums, delegates but only on discriminated unions or record types. + The attributes 'NoEquality', 'ReferenceEquality', 'StructuralEquality', 'NoComparison' and 'StructuralComparison' aren't meant to be used on adhoc classes, interfaces, structures, enums, delegates but only on discriminated unions or record types. + + The source file '{0}' (at position {1}/{2}) already appeared in the compilation list (at position {3}/{4}). Please verify that it is included only once in the project file. Zdrojový soubor {0} (na pozici {1}/{2}) se už zobrazil v seznamu kompilací (na pozici {3}/{4}). Ověřte prosím, že je v souboru projektu zahrnutý jen jednou. diff --git a/src/Compiler/xlf/FSComp.txt.de.xlf b/src/Compiler/xlf/FSComp.txt.de.xlf index d0feebf9d97..f8fee3b2226 100644 --- a/src/Compiler/xlf/FSComp.txt.de.xlf +++ b/src/Compiler/xlf/FSComp.txt.de.xlf @@ -12,6 +12,11 @@ Alle Elemente eines Arrays müssen implizit in den Typ des ersten Elements konvertiert werden. Hierbei handelt es sich um ein Tupel der Länge {0} vom Typ\n {1} \nDieses Element ist ein Tupel der Länge {2} vom Typ\n {3}. \n + + The attributes 'NoEquality', 'ReferenceEquality', 'StructuralEquality', 'NoComparison' and 'StructuralComparison' aren't meant to be used on adhoc classes, interfaces, structures, enums, delegates but only on discriminated unions or record types. + The attributes 'NoEquality', 'ReferenceEquality', 'StructuralEquality', 'NoComparison' and 'StructuralComparison' aren't meant to be used on adhoc classes, interfaces, structures, enums, delegates but only on discriminated unions or record types. + + The source file '{0}' (at position {1}/{2}) already appeared in the compilation list (at position {3}/{4}). Please verify that it is included only once in the project file. Die Quelldatei „{0}“ (an Position {1}/{2}) wurde bereits in der Kompilierungsliste angezeigt (an Position {3}/{4}). Bitte stellen Sie sicher, dass sie nur einmal in der Projektdatei enthalten ist. diff --git a/src/Compiler/xlf/FSComp.txt.es.xlf b/src/Compiler/xlf/FSComp.txt.es.xlf index fae7ec8f032..36b4f05f01a 100644 --- a/src/Compiler/xlf/FSComp.txt.es.xlf +++ b/src/Compiler/xlf/FSComp.txt.es.xlf @@ -12,6 +12,11 @@ Todos los elementos de una matriz deben convertirse implícitamente en el tipo del primer elemento, que aquí es una tupla de longitud {0} de tipo\n {1} \nEste elemento es una tupla de longitud {2} de tipo\n {3} \n + + The attributes 'NoEquality', 'ReferenceEquality', 'StructuralEquality', 'NoComparison' and 'StructuralComparison' aren't meant to be used on adhoc classes, interfaces, structures, enums, delegates but only on discriminated unions or record types. + The attributes 'NoEquality', 'ReferenceEquality', 'StructuralEquality', 'NoComparison' and 'StructuralComparison' aren't meant to be used on adhoc classes, interfaces, structures, enums, delegates but only on discriminated unions or record types. + + The source file '{0}' (at position {1}/{2}) already appeared in the compilation list (at position {3}/{4}). Please verify that it is included only once in the project file. El archivo de origen "{0}" (en la posición {1}/{2}) ya aparece en la lista de compilación (en la posición {3}/{4}). Compruebe que solo se incluya una vez en el archivo del proyecto. diff --git a/src/Compiler/xlf/FSComp.txt.fr.xlf b/src/Compiler/xlf/FSComp.txt.fr.xlf index 4a98252d56f..9cf7d949b35 100644 --- a/src/Compiler/xlf/FSComp.txt.fr.xlf +++ b/src/Compiler/xlf/FSComp.txt.fr.xlf @@ -12,6 +12,11 @@ Tous les éléments d’un tableau doivent être implicitement convertibles en type du premier élément, qui est ici un tuple de longueur {0} de type\n {1} \nCet élément est un tuple de longueur {2} de type\n {3} \n + + The attributes 'NoEquality', 'ReferenceEquality', 'StructuralEquality', 'NoComparison' and 'StructuralComparison' aren't meant to be used on adhoc classes, interfaces, structures, enums, delegates but only on discriminated unions or record types. + The attributes 'NoEquality', 'ReferenceEquality', 'StructuralEquality', 'NoComparison' and 'StructuralComparison' aren't meant to be used on adhoc classes, interfaces, structures, enums, delegates but only on discriminated unions or record types. + + The source file '{0}' (at position {1}/{2}) already appeared in the compilation list (at position {3}/{4}). Please verify that it is included only once in the project file. Le fichier source « {0} » (à la position {1}/{2}) apparaît déjà dans la liste de compilation (à la position {3}/{4}). Vérifiez qu’il n’est inclus qu’une seule fois dans le fichier projet. diff --git a/src/Compiler/xlf/FSComp.txt.it.xlf b/src/Compiler/xlf/FSComp.txt.it.xlf index 969c6716e2f..9e33237f5b7 100644 --- a/src/Compiler/xlf/FSComp.txt.it.xlf +++ b/src/Compiler/xlf/FSComp.txt.it.xlf @@ -12,6 +12,11 @@ Tutti gli elementi di una matrice devono essere convertibili in modo implicito nel tipo del primo elemento, che qui è una tupla di lunghezza {0} di tipo\n {1} \nQuesto elemento è una tupla di lunghezza {2} di tipo\n {3} \n + + The attributes 'NoEquality', 'ReferenceEquality', 'StructuralEquality', 'NoComparison' and 'StructuralComparison' aren't meant to be used on adhoc classes, interfaces, structures, enums, delegates but only on discriminated unions or record types. + The attributes 'NoEquality', 'ReferenceEquality', 'StructuralEquality', 'NoComparison' and 'StructuralComparison' aren't meant to be used on adhoc classes, interfaces, structures, enums, delegates but only on discriminated unions or record types. + + The source file '{0}' (at position {1}/{2}) already appeared in the compilation list (at position {3}/{4}). Please verify that it is included only once in the project file. Il file di origine '{0}' (nella posizione {1}/{2}) è già presente nell'elenco di compilazione (nella posizione {3}/{4}). Verificare che sia incluso solo una volta nel file di progetto. diff --git a/src/Compiler/xlf/FSComp.txt.ja.xlf b/src/Compiler/xlf/FSComp.txt.ja.xlf index 440e83c32b9..6e1cf9c966f 100644 --- a/src/Compiler/xlf/FSComp.txt.ja.xlf +++ b/src/Compiler/xlf/FSComp.txt.ja.xlf @@ -12,6 +12,11 @@ 配列のすべての要素は、最初の要素の型に暗黙的に変換できる必要があります。これは、型の長さ {0} のタプルです\n {1} \nこの要素は、型の長さ {2} のタプルです\n {3} \n + + The attributes 'NoEquality', 'ReferenceEquality', 'StructuralEquality', 'NoComparison' and 'StructuralComparison' aren't meant to be used on adhoc classes, interfaces, structures, enums, delegates but only on discriminated unions or record types. + The attributes 'NoEquality', 'ReferenceEquality', 'StructuralEquality', 'NoComparison' and 'StructuralComparison' aren't meant to be used on adhoc classes, interfaces, structures, enums, delegates but only on discriminated unions or record types. + + The source file '{0}' (at position {1}/{2}) already appeared in the compilation list (at position {3}/{4}). Please verify that it is included only once in the project file. ソース ファイル '{0}' (位置 {1}/{2}) は、コンパイル リスト (位置 {3}/{4}) に既に存在します。プロジェクト ファイルに 1 回だけ含まれていることを確認してください。 diff --git a/src/Compiler/xlf/FSComp.txt.ko.xlf b/src/Compiler/xlf/FSComp.txt.ko.xlf index 1a55695d885..d326ff34ba8 100644 --- a/src/Compiler/xlf/FSComp.txt.ko.xlf +++ b/src/Compiler/xlf/FSComp.txt.ko.xlf @@ -12,6 +12,11 @@ 배열의 모든 요소는 첫 번째 요소의 형식으로 암시적으로 변환할 수 있어야 합니다. 여기서는 형식이 \n {1}이고 길이가 {0}인 튜플입니다. \n이 요소는 형식이 \n {3}이고 길이가 {2}인 튜플입니다. \n + + The attributes 'NoEquality', 'ReferenceEquality', 'StructuralEquality', 'NoComparison' and 'StructuralComparison' aren't meant to be used on adhoc classes, interfaces, structures, enums, delegates but only on discriminated unions or record types. + The attributes 'NoEquality', 'ReferenceEquality', 'StructuralEquality', 'NoComparison' and 'StructuralComparison' aren't meant to be used on adhoc classes, interfaces, structures, enums, delegates but only on discriminated unions or record types. + + The source file '{0}' (at position {1}/{2}) already appeared in the compilation list (at position {3}/{4}). Please verify that it is included only once in the project file. '{0}' 원본 파일(위치: {1}/{2})이 이미 컴파일 목록에 있습니다(위치{3}/{4}). 프로젝트 파일에 한 번만 포함되어 있는지 확인하세요. diff --git a/src/Compiler/xlf/FSComp.txt.pl.xlf b/src/Compiler/xlf/FSComp.txt.pl.xlf index fdf34864db0..4b945dc01f8 100644 --- a/src/Compiler/xlf/FSComp.txt.pl.xlf +++ b/src/Compiler/xlf/FSComp.txt.pl.xlf @@ -12,6 +12,11 @@ Wszystkie elementy tablicy muszą być niejawnie konwertowalne na typ pierwszego elementu, który w tym miejscu jest krotką o długości {0} typu\n {1} \nTen element jest krotką o długości {2} typu\n {3} \n + + The attributes 'NoEquality', 'ReferenceEquality', 'StructuralEquality', 'NoComparison' and 'StructuralComparison' aren't meant to be used on adhoc classes, interfaces, structures, enums, delegates but only on discriminated unions or record types. + The attributes 'NoEquality', 'ReferenceEquality', 'StructuralEquality', 'NoComparison' and 'StructuralComparison' aren't meant to be used on adhoc classes, interfaces, structures, enums, delegates but only on discriminated unions or record types. + + The source file '{0}' (at position {1}/{2}) already appeared in the compilation list (at position {3}/{4}). Please verify that it is included only once in the project file. Plik źródłowy „{0}” (na pozycji {1}/{2}) już pojawił się na liście kompilacji (na pozycji {3}/{4}). Sprawdź, czy jest on uwzględniony tylko raz w pliku projektu. diff --git a/src/Compiler/xlf/FSComp.txt.pt-BR.xlf b/src/Compiler/xlf/FSComp.txt.pt-BR.xlf index 86ede3eed08..6fa8bdfc55a 100644 --- a/src/Compiler/xlf/FSComp.txt.pt-BR.xlf +++ b/src/Compiler/xlf/FSComp.txt.pt-BR.xlf @@ -12,6 +12,11 @@ Todos os elementos de uma matriz devem ser implicitamente conversíveis ao tipo do primeiro elemento, que aqui é uma tupla de comprimento {0} do tipo\n {1} \nEste elemento é uma tupla de comprimento {2} do tipo\n {3} \n + + The attributes 'NoEquality', 'ReferenceEquality', 'StructuralEquality', 'NoComparison' and 'StructuralComparison' aren't meant to be used on adhoc classes, interfaces, structures, enums, delegates but only on discriminated unions or record types. + The attributes 'NoEquality', 'ReferenceEquality', 'StructuralEquality', 'NoComparison' and 'StructuralComparison' aren't meant to be used on adhoc classes, interfaces, structures, enums, delegates but only on discriminated unions or record types. + + The source file '{0}' (at position {1}/{2}) already appeared in the compilation list (at position {3}/{4}). Please verify that it is included only once in the project file. O arquivo fonte '{0}' (na posição {1}/{2} ) já apareceu na lista de compilação (na posição {3}/{4}). Verifique se ele foi incluído apenas uma vez no arquivo do projeto. diff --git a/src/Compiler/xlf/FSComp.txt.ru.xlf b/src/Compiler/xlf/FSComp.txt.ru.xlf index e5844060d67..de897c0729c 100644 --- a/src/Compiler/xlf/FSComp.txt.ru.xlf +++ b/src/Compiler/xlf/FSComp.txt.ru.xlf @@ -12,6 +12,11 @@ Все элементы массива должны поддерживать неявное преобразование в тип первого элемента, который здесь является кортежем длиной {0} типа\n {1} \nЭтот элемент является кортежем длиной {2} типа\n {3} \n + + The attributes 'NoEquality', 'ReferenceEquality', 'StructuralEquality', 'NoComparison' and 'StructuralComparison' aren't meant to be used on adhoc classes, interfaces, structures, enums, delegates but only on discriminated unions or record types. + The attributes 'NoEquality', 'ReferenceEquality', 'StructuralEquality', 'NoComparison' and 'StructuralComparison' aren't meant to be used on adhoc classes, interfaces, structures, enums, delegates but only on discriminated unions or record types. + + The source file '{0}' (at position {1}/{2}) already appeared in the compilation list (at position {3}/{4}). Please verify that it is included only once in the project file. Исходный файл "{0}" (в позиции {1}/{2}) уже присутствует в списке компиляции (в позиции {3}/{4}). Убедитесь, что он включен в файл проекта только один раз. diff --git a/src/Compiler/xlf/FSComp.txt.tr.xlf b/src/Compiler/xlf/FSComp.txt.tr.xlf index 6e5505f1b7f..c61fd625ea5 100644 --- a/src/Compiler/xlf/FSComp.txt.tr.xlf +++ b/src/Compiler/xlf/FSComp.txt.tr.xlf @@ -12,6 +12,11 @@ Bir dizinin tüm öğeleri örtük olarak ilk öğenin türüne dönüştürülebilir olmalıdır. Burada ilk öğe {0} uzunluğunda türü\n {1} \nolan bir demet. Bu öğe ise {2} uzunluğunda türü\n {3} \nolan bir demet. + + The attributes 'NoEquality', 'ReferenceEquality', 'StructuralEquality', 'NoComparison' and 'StructuralComparison' aren't meant to be used on adhoc classes, interfaces, structures, enums, delegates but only on discriminated unions or record types. + The attributes 'NoEquality', 'ReferenceEquality', 'StructuralEquality', 'NoComparison' and 'StructuralComparison' aren't meant to be used on adhoc classes, interfaces, structures, enums, delegates but only on discriminated unions or record types. + + The source file '{0}' (at position {1}/{2}) already appeared in the compilation list (at position {3}/{4}). Please verify that it is included only once in the project file. Kaynak dosya '{0}' ({1}/{2} konumunda) derleme listesinde ({3}/{4} konumunda) zaten göründü. Lütfen proje dosyasına yalnızca bir kez eklendiğinden emin olun. diff --git a/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf b/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf index 3e5248d2115..353324ca950 100644 --- a/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf +++ b/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf @@ -12,6 +12,11 @@ 数组的所有元素必须可隐式转换为第一个元素的类型,这是一个长度为 {0} 的类型的元组\n {1} \n此元素是长度为 {2} 类型的元组\n {3} \n + + The attributes 'NoEquality', 'ReferenceEquality', 'StructuralEquality', 'NoComparison' and 'StructuralComparison' aren't meant to be used on adhoc classes, interfaces, structures, enums, delegates but only on discriminated unions or record types. + The attributes 'NoEquality', 'ReferenceEquality', 'StructuralEquality', 'NoComparison' and 'StructuralComparison' aren't meant to be used on adhoc classes, interfaces, structures, enums, delegates but only on discriminated unions or record types. + + The source file '{0}' (at position {1}/{2}) already appeared in the compilation list (at position {3}/{4}). Please verify that it is included only once in the project file. 源文件“{0}”(位于位置 {1}/{2})已出现在编译列表(位于位置 {3}/{4})中。请确认该文件仅包含在项目文件中一次。 diff --git a/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf b/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf index a1b3568925f..58620aef80f 100644 --- a/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf +++ b/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf @@ -12,6 +12,11 @@ 陣列的所有元素必須以隱含方式轉換成第一個元素的類型,這是類型為\n {1} \n的元組長度 {0}此元素是類型為\n {3} \n的元組長度{2} + + The attributes 'NoEquality', 'ReferenceEquality', 'StructuralEquality', 'NoComparison' and 'StructuralComparison' aren't meant to be used on adhoc classes, interfaces, structures, enums, delegates but only on discriminated unions or record types. + The attributes 'NoEquality', 'ReferenceEquality', 'StructuralEquality', 'NoComparison' and 'StructuralComparison' aren't meant to be used on adhoc classes, interfaces, structures, enums, delegates but only on discriminated unions or record types. + + The source file '{0}' (at position {1}/{2}) already appeared in the compilation list (at position {3}/{4}). Please verify that it is included only once in the project file. 來源檔案 '{0}' ( 位於位置 {1}/{2}) 已出現在編譯清單 ( 位於位置 {3}/{4})。請確認它在專案檔中只包含一次。 From e4a667636618a4091036a9671f1ee336ea12c482 Mon Sep 17 00:00:00 2001 From: Gauthier Segay Date: Fri, 19 Jan 2024 20:03:21 +0100 Subject: [PATCH 2/2] adding a test case that checks two new error messages (augInvalidAttrsForFSharpObjectModelType, augInvalidAttrForFsharpObjectModelType) --- .../Checking/AugmentWithHashCompare.fs | 103 ++++++++++++------ src/Compiler/FSComp.txt | 3 +- src/Compiler/xlf/FSComp.txt.cs.xlf | 9 +- src/Compiler/xlf/FSComp.txt.de.xlf | 9 +- src/Compiler/xlf/FSComp.txt.es.xlf | 9 +- src/Compiler/xlf/FSComp.txt.fr.xlf | 9 +- src/Compiler/xlf/FSComp.txt.it.xlf | 9 +- src/Compiler/xlf/FSComp.txt.ja.xlf | 9 +- src/Compiler/xlf/FSComp.txt.ko.xlf | 9 +- src/Compiler/xlf/FSComp.txt.pl.xlf | 9 +- src/Compiler/xlf/FSComp.txt.pt-BR.xlf | 9 +- src/Compiler/xlf/FSComp.txt.ru.xlf | 9 +- src/Compiler/xlf/FSComp.txt.tr.xlf | 9 +- src/Compiler/xlf/FSComp.txt.zh-Hans.xlf | 9 +- src/Compiler/xlf/FSComp.txt.zh-Hant.xlf | 9 +- .../TypeAugmentationAttributesTests.fs | 12 ++ .../attributes.on.nonok.types.fsx | 32 ++++++ .../attributes.on.nonok.types.fsx.err.bsl | 25 +++++ .../attributes.on.nonok.types.fsx.il.bsl | 0 .../FSharp.Compiler.ComponentTests.fsproj | 4 +- 20 files changed, 234 insertions(+), 62 deletions(-) create mode 100644 tests/FSharp.Compiler.ComponentTests/ErrorMessages/TypeAugmentationAttributes/TypeAugmentationAttributesTests.fs create mode 100644 tests/FSharp.Compiler.ComponentTests/ErrorMessages/TypeAugmentationAttributes/attributes.on.nonok.types.fsx create mode 100644 tests/FSharp.Compiler.ComponentTests/ErrorMessages/TypeAugmentationAttributes/attributes.on.nonok.types.fsx.err.bsl create mode 100644 tests/FSharp.Compiler.ComponentTests/ErrorMessages/TypeAugmentationAttributes/attributes.on.nonok.types.fsx.il.bsl diff --git a/src/Compiler/Checking/AugmentWithHashCompare.fs b/src/Compiler/Checking/AugmentWithHashCompare.fs index f96bd3104f7..442524f8fd4 100644 --- a/src/Compiler/Checking/AugmentWithHashCompare.fs +++ b/src/Compiler/Checking/AugmentWithHashCompare.fs @@ -1004,15 +1004,20 @@ let canBeAugmentedWithCompare g (tycon: Tycon) = tycon.IsUnionTycon || tycon.IsRecordTycon || isTrueFSharpStructTycon g tycon let getAugmentationAttribs g (tycon: Tycon) = + let hasAttrAndName (attr: BuiltinAttribInfo) = + match TryFindFSharpBoolAttribute g attr tycon.Attribs with + | Some b -> Some(struct(b, attr.TyconRef.DisplayName)) + | None -> None + canBeAugmentedWithEquals g tycon, canBeAugmentedWithCompare g tycon, - TryFindFSharpBoolAttribute g g.attrib_NoEqualityAttribute tycon.Attribs, - TryFindFSharpBoolAttribute g g.attrib_CustomEqualityAttribute tycon.Attribs, - TryFindFSharpBoolAttribute g g.attrib_ReferenceEqualityAttribute tycon.Attribs, - TryFindFSharpBoolAttribute g g.attrib_StructuralEqualityAttribute tycon.Attribs, - TryFindFSharpBoolAttribute g g.attrib_NoComparisonAttribute tycon.Attribs, - TryFindFSharpBoolAttribute g g.attrib_CustomComparisonAttribute tycon.Attribs, - TryFindFSharpBoolAttribute g g.attrib_StructuralComparisonAttribute tycon.Attribs + hasAttrAndName g.attrib_NoEqualityAttribute, + hasAttrAndName g.attrib_CustomEqualityAttribute, + hasAttrAndName g.attrib_ReferenceEqualityAttribute, + hasAttrAndName g.attrib_StructuralEqualityAttribute, + hasAttrAndName g.attrib_NoComparisonAttribute, + hasAttrAndName g.attrib_CustomComparisonAttribute, + hasAttrAndName g.attrib_StructuralComparisonAttribute let CheckAugmentationAttribs isImplementation g amap (tycon: Tycon) = let m = tycon.Range @@ -1026,65 +1031,95 @@ let CheckAugmentationAttribs isImplementation g amap (tycon: Tycon) = | _, _, None, None, None, None, None, None, None // [] on union/record/struct - | true, _, None, Some true, None, None, None, Some true, None + | true, _, None, Some (true,_), None, None, None, Some (true,_), None // [] on union/record/struct - | true, _, None, Some true, None, None, Some true, None, None -> () + | true, _, None, Some (true,_), None, None, Some (true,_), None, None -> () // [] on union/record/struct - | true, _, None, None, Some true, None, Some true, None, None + | true, _, None, None, Some (true,_), None, Some (true,_), None, None // [] on union/record/struct - | true, _, None, None, Some true, None, None, None, None -> + | true, _, None, None, Some (true,_), None, None, None, None -> if isTrueFSharpStructTycon g tycon then errorR (Error(FSComp.SR.augNoRefEqualsOnStruct (), m)) else () // [] on union/record/struct - | true, true, None, None, None, Some true, None, None, Some true + | true, true, None, None, None, Some (true,_), None, None, Some (true,_) // [] - | true, _, None, None, None, Some true, Some true, None, None + | true, _, None, None, None, Some (true,_), Some (true,_), None, None // [] - | true, _, None, None, None, Some true, None, Some true, None + | true, _, None, None, None, Some (true,_), None, Some (true,_), None // [] on anything - | _, _, None, None, None, None, Some true, None, None + | _, _, None, None, None, None, Some (true,_), None, None // [] on anything - | _, _, Some true, None, None, None, Some true, None, None -> () + | _, _, Some (true,_), None, None, None, Some (true,_), None, None -> () // THESE ARE THE ERROR CASES // [] - | _, _, Some true, _, _, _, None, _, _ -> errorR (Error(FSComp.SR.augNoEqualityNeedsNoComparison (), m)) + | _, _, Some (true,_), _, _, _, None, _, _ -> errorR (Error(FSComp.SR.augNoEqualityNeedsNoComparison (), m)) // [] - | true, true, _, _, _, None, _, _, Some true -> errorR (Error(FSComp.SR.augStructCompNeedsStructEquality (), m)) + | true, true, _, _, _, None, _, _, Some (true,_) -> errorR (Error(FSComp.SR.augStructCompNeedsStructEquality (), m)) // [] - | true, _, _, _, _, Some true, None, _, None -> errorR (Error(FSComp.SR.augStructEqNeedsNoCompOrStructComp (), m)) + | true, _, _, _, _, Some (true,_), None, _, None -> errorR (Error(FSComp.SR.augStructEqNeedsNoCompOrStructComp (), m)) // [] - | true, _, _, Some true, _, _, None, None, _ -> errorR (Error(FSComp.SR.augCustomEqNeedsNoCompOrCustomComp (), m)) + | true, _, _, Some (true,_), _, _, None, None, _ -> errorR (Error(FSComp.SR.augCustomEqNeedsNoCompOrCustomComp (), m)) // [] - | true, _, _, _, Some true, Some true, _, _, _ + | true, _, _, _, Some (true,_), Some (true,_), _, _, _ // [] - | true, _, _, _, Some true, _, _, _, Some true -> errorR (Error(FSComp.SR.augTypeCantHaveRefEqAndStructAttrs (), m)) + | true, _, _, _, Some (true,_), _, _, _, Some (true,_) -> errorR (Error(FSComp.SR.augTypeCantHaveRefEqAndStructAttrs (), m)) // non augmented type, [] // non augmented type, [] // non augmented type, [] - | false, _, _, _, Some true, _, _, _, _ - | false, _, _, _, _, Some true, _, _, _ - | false, _, _, _, _, _, _, _, Some true -> errorR (Error(FSComp.SR.augOnlyCertainTypesCanHaveAttrs (), m)) + | false, _, _, _, Some (true,_), _, _, _, _ + | false, _, _, _, _, Some (true,_), _, _, _ + | false, _, _, _, _, _, _, _, Some (true,_) -> errorR (Error(FSComp.SR.augOnlyCertainTypesCanHaveAttrs (), m)) // All other cases | _ -> if tycon.IsFSharpObjectModelTycon then - errorR (Error(FSComp.SR.augInvalidAttrsForFSharpObjectModelType(), m)) + + let enumAttributeNames = + [ + match attribs with + | _,_,_,Some a,_,_,_,_,_ -> a + | _ -> () + match attribs with + | _,_,_,_,Some a,_,_,_,_ -> a + | _ -> () + match attribs with + | _,_,_,_,_,Some a,_,_,_ -> a + | _ -> () + match attribs with + | _,_,_,_,_,_,Some a,_,_ -> a + | _ -> () + match attribs with + | _,_,_,_,_,_,_,Some a,_ -> a + | _ -> () + match attribs with + | _,_,_,_,_,_,_,_,Some a -> a + | _ -> () + ] + |> List.map (fun struct(_,b) -> b) + match enumAttributeNames with + | [] -> + assert false + errorR (Error(FSComp.SR.augInvalidAttrs (), m)) + | [attrName] -> errorR (Error(FSComp.SR.augInvalidAttrForFSharpObjectModelType attrName, m)) + | attrs -> + let names = attrs |> String.concat ", " + errorR (Error(FSComp.SR.augInvalidAttrsForFSharpObjectModelType names, m)) else errorR (Error(FSComp.SR.augInvalidAttrs (), m)) @@ -1107,21 +1142,21 @@ let CheckAugmentationAttribs isImplementation g amap (tycon: Tycon) = match attribs with // [] + any equality semantics - | _, _, Some true, _, _, _, _, _, _ when (hasExplicitEquals || hasExplicitGenericEquals) -> + | _, _, Some (true,_), _, _, _, _, _, _ when (hasExplicitEquals || hasExplicitGenericEquals) -> warning (Error(FSComp.SR.augNoEqNeedsNoObjEquals (), m)) // [] + any comparison semantics - | _, _, _, _, _, _, Some true, _, _ when (hasExplicitICompare || hasExplicitIGenericCompare) -> + | _, _, _, _, _, _, Some (true,_), _, _ when (hasExplicitICompare || hasExplicitIGenericCompare) -> warning (Error(FSComp.SR.augNoCompCantImpIComp (), m)) // [] + no explicit override Object.Equals + no explicit IStructuralEquatable - | _, _, _, Some true, _, _, _, _, _ when isImplementation && not hasExplicitEquals && not hasExplicitGenericEquals -> + | _, _, _, Some (true,_), _, _, _, _, _ when isImplementation && not hasExplicitEquals && not hasExplicitGenericEquals -> errorR (Error(FSComp.SR.augCustomEqNeedsObjEquals (), m)) // [] + no explicit IComparable + no explicit IStructuralComparable - | _, _, _, _, _, _, _, Some true, _ when isImplementation && not hasExplicitICompare && not hasExplicitIGenericCompare -> + | _, _, _, _, _, _, _, Some (true,_), _ when isImplementation && not hasExplicitICompare && not hasExplicitIGenericCompare -> errorR (Error(FSComp.SR.augCustomCompareNeedsIComp (), m)) // [] + any equality semantics - | _, _, _, _, Some true, _, _, _, _ when (hasExplicitEquals || hasExplicitIGenericCompare) -> + | _, _, _, _, Some (true,_), _, _, _, _ when (hasExplicitEquals || hasExplicitIGenericCompare) -> errorR (Error(FSComp.SR.augRefEqCantHaveObjEquals (), m)) | _ -> () @@ -1136,9 +1171,9 @@ let TyconIsCandidateForAugmentationWithCompare (g: TcGlobals) (tycon: Tycon) = // [< >] | true, true, None, None, None, None, None, None, None // [] - | true, true, None, None, None, Some true, None, None, Some true + | true, true, None, None, None, Some (true,_), None, None, Some (true,_) // [] - | true, true, None, None, None, None, None, None, Some true -> true + | true, true, None, None, None, None, None, None, Some (true,_) -> true // other cases | _ -> false @@ -1155,7 +1190,7 @@ let TyconIsCandidateForAugmentationWithEquals (g: TcGlobals) (tycon: Tycon) = | true, _, None, None, None, None, _, _, _ // [] // [] - | true, _, None, None, None, Some true, _, _, _ -> true + | true, _, None, None, None, Some (true,_), _, _, _ -> true // other cases | _ -> false diff --git a/src/Compiler/FSComp.txt b/src/Compiler/FSComp.txt index 1047cdb2c5f..3ea73f5cf3f 100644 --- a/src/Compiler/FSComp.txt +++ b/src/Compiler/FSComp.txt @@ -227,7 +227,8 @@ astDeprecatedIndexerNotation,"This indexer notation has been removed from the F# 386,augNoEqNeedsNoObjEquals,"A type with attribute 'NoEquality' should not usually have an explicit implementation of 'Object.Equals(obj)'. Disable this warning if this is intentional for interoperability purposes" 386,augNoCompCantImpIComp,"A type with attribute 'NoComparison' should not usually have an explicit implementation of 'System.IComparable', 'System.IComparable<_>' or 'System.Collections.IStructuralComparable'. Disable this warning if this is intentional for interoperability purposes" 387,augCustomEqNeedsNoCompOrCustomComp,"The 'CustomEquality' attribute must be used in conjunction with the 'NoComparison' or 'CustomComparison' attributes" -388,augInvalidAttrsForFSharpObjectModelType,"The attributes 'NoEquality', 'ReferenceEquality', 'StructuralEquality', 'NoComparison' and 'StructuralComparison' aren't meant to be used on adhoc classes, interfaces, structures, enums, delegates but only on discriminated unions or record types." +388,augInvalidAttrsForFSharpObjectModelType,"The attributes %s are only meant for discriminated unions or record types." +388,augInvalidAttrForFSharpObjectModelType,"The attribute %s is only meant for discriminated unions or record types." forPositionalSpecifiersNotPermitted,"Positional specifiers are not permitted in format strings" forMissingFormatSpecifier,"Missing format specifier" forFlagSetTwice,"'%s' flag set twice" diff --git a/src/Compiler/xlf/FSComp.txt.cs.xlf b/src/Compiler/xlf/FSComp.txt.cs.xlf index 6f9e712c353..d16b4eae7ea 100644 --- a/src/Compiler/xlf/FSComp.txt.cs.xlf +++ b/src/Compiler/xlf/FSComp.txt.cs.xlf @@ -12,9 +12,14 @@ Všechny prvky pole musí být implicitně převoditelné na typ prvního elementu, což je řazená kolekce členů o délce {0} typu\n {1} \nTento element je řazená kolekce členů o délce {2} typu\n {3} \n + + The attribute {0} is only meant for discriminated unions or record types. + The attribute {0} is only meant for discriminated unions or record types. + + - The attributes 'NoEquality', 'ReferenceEquality', 'StructuralEquality', 'NoComparison' and 'StructuralComparison' aren't meant to be used on adhoc classes, interfaces, structures, enums, delegates but only on discriminated unions or record types. - The attributes 'NoEquality', 'ReferenceEquality', 'StructuralEquality', 'NoComparison' and 'StructuralComparison' aren't meant to be used on adhoc classes, interfaces, structures, enums, delegates but only on discriminated unions or record types. + The attributes {0} are only meant for discriminated unions or record types. + The attributes {0} are only meant for discriminated unions or record types. diff --git a/src/Compiler/xlf/FSComp.txt.de.xlf b/src/Compiler/xlf/FSComp.txt.de.xlf index f8fee3b2226..379741cdac2 100644 --- a/src/Compiler/xlf/FSComp.txt.de.xlf +++ b/src/Compiler/xlf/FSComp.txt.de.xlf @@ -12,9 +12,14 @@ Alle Elemente eines Arrays müssen implizit in den Typ des ersten Elements konvertiert werden. Hierbei handelt es sich um ein Tupel der Länge {0} vom Typ\n {1} \nDieses Element ist ein Tupel der Länge {2} vom Typ\n {3}. \n + + The attribute {0} is only meant for discriminated unions or record types. + The attribute {0} is only meant for discriminated unions or record types. + + - The attributes 'NoEquality', 'ReferenceEquality', 'StructuralEquality', 'NoComparison' and 'StructuralComparison' aren't meant to be used on adhoc classes, interfaces, structures, enums, delegates but only on discriminated unions or record types. - The attributes 'NoEquality', 'ReferenceEquality', 'StructuralEquality', 'NoComparison' and 'StructuralComparison' aren't meant to be used on adhoc classes, interfaces, structures, enums, delegates but only on discriminated unions or record types. + The attributes {0} are only meant for discriminated unions or record types. + The attributes {0} are only meant for discriminated unions or record types. diff --git a/src/Compiler/xlf/FSComp.txt.es.xlf b/src/Compiler/xlf/FSComp.txt.es.xlf index 36b4f05f01a..f8102fcbc95 100644 --- a/src/Compiler/xlf/FSComp.txt.es.xlf +++ b/src/Compiler/xlf/FSComp.txt.es.xlf @@ -12,9 +12,14 @@ Todos los elementos de una matriz deben convertirse implícitamente en el tipo del primer elemento, que aquí es una tupla de longitud {0} de tipo\n {1} \nEste elemento es una tupla de longitud {2} de tipo\n {3} \n + + The attribute {0} is only meant for discriminated unions or record types. + The attribute {0} is only meant for discriminated unions or record types. + + - The attributes 'NoEquality', 'ReferenceEquality', 'StructuralEquality', 'NoComparison' and 'StructuralComparison' aren't meant to be used on adhoc classes, interfaces, structures, enums, delegates but only on discriminated unions or record types. - The attributes 'NoEquality', 'ReferenceEquality', 'StructuralEquality', 'NoComparison' and 'StructuralComparison' aren't meant to be used on adhoc classes, interfaces, structures, enums, delegates but only on discriminated unions or record types. + The attributes {0} are only meant for discriminated unions or record types. + The attributes {0} are only meant for discriminated unions or record types. diff --git a/src/Compiler/xlf/FSComp.txt.fr.xlf b/src/Compiler/xlf/FSComp.txt.fr.xlf index 9cf7d949b35..b791b7da0d0 100644 --- a/src/Compiler/xlf/FSComp.txt.fr.xlf +++ b/src/Compiler/xlf/FSComp.txt.fr.xlf @@ -12,9 +12,14 @@ Tous les éléments d’un tableau doivent être implicitement convertibles en type du premier élément, qui est ici un tuple de longueur {0} de type\n {1} \nCet élément est un tuple de longueur {2} de type\n {3} \n + + The attribute {0} is only meant for discriminated unions or record types. + The attribute {0} is only meant for discriminated unions or record types. + + - The attributes 'NoEquality', 'ReferenceEquality', 'StructuralEquality', 'NoComparison' and 'StructuralComparison' aren't meant to be used on adhoc classes, interfaces, structures, enums, delegates but only on discriminated unions or record types. - The attributes 'NoEquality', 'ReferenceEquality', 'StructuralEquality', 'NoComparison' and 'StructuralComparison' aren't meant to be used on adhoc classes, interfaces, structures, enums, delegates but only on discriminated unions or record types. + The attributes {0} are only meant for discriminated unions or record types. + The attributes {0} are only meant for discriminated unions or record types. diff --git a/src/Compiler/xlf/FSComp.txt.it.xlf b/src/Compiler/xlf/FSComp.txt.it.xlf index 9e33237f5b7..a3bea98fc30 100644 --- a/src/Compiler/xlf/FSComp.txt.it.xlf +++ b/src/Compiler/xlf/FSComp.txt.it.xlf @@ -12,9 +12,14 @@ Tutti gli elementi di una matrice devono essere convertibili in modo implicito nel tipo del primo elemento, che qui è una tupla di lunghezza {0} di tipo\n {1} \nQuesto elemento è una tupla di lunghezza {2} di tipo\n {3} \n + + The attribute {0} is only meant for discriminated unions or record types. + The attribute {0} is only meant for discriminated unions or record types. + + - The attributes 'NoEquality', 'ReferenceEquality', 'StructuralEquality', 'NoComparison' and 'StructuralComparison' aren't meant to be used on adhoc classes, interfaces, structures, enums, delegates but only on discriminated unions or record types. - The attributes 'NoEquality', 'ReferenceEquality', 'StructuralEquality', 'NoComparison' and 'StructuralComparison' aren't meant to be used on adhoc classes, interfaces, structures, enums, delegates but only on discriminated unions or record types. + The attributes {0} are only meant for discriminated unions or record types. + The attributes {0} are only meant for discriminated unions or record types. diff --git a/src/Compiler/xlf/FSComp.txt.ja.xlf b/src/Compiler/xlf/FSComp.txt.ja.xlf index 6e1cf9c966f..12ae6f1073f 100644 --- a/src/Compiler/xlf/FSComp.txt.ja.xlf +++ b/src/Compiler/xlf/FSComp.txt.ja.xlf @@ -12,9 +12,14 @@ 配列のすべての要素は、最初の要素の型に暗黙的に変換できる必要があります。これは、型の長さ {0} のタプルです\n {1} \nこの要素は、型の長さ {2} のタプルです\n {3} \n + + The attribute {0} is only meant for discriminated unions or record types. + The attribute {0} is only meant for discriminated unions or record types. + + - The attributes 'NoEquality', 'ReferenceEquality', 'StructuralEquality', 'NoComparison' and 'StructuralComparison' aren't meant to be used on adhoc classes, interfaces, structures, enums, delegates but only on discriminated unions or record types. - The attributes 'NoEquality', 'ReferenceEquality', 'StructuralEquality', 'NoComparison' and 'StructuralComparison' aren't meant to be used on adhoc classes, interfaces, structures, enums, delegates but only on discriminated unions or record types. + The attributes {0} are only meant for discriminated unions or record types. + The attributes {0} are only meant for discriminated unions or record types. diff --git a/src/Compiler/xlf/FSComp.txt.ko.xlf b/src/Compiler/xlf/FSComp.txt.ko.xlf index d326ff34ba8..7c7a057e981 100644 --- a/src/Compiler/xlf/FSComp.txt.ko.xlf +++ b/src/Compiler/xlf/FSComp.txt.ko.xlf @@ -12,9 +12,14 @@ 배열의 모든 요소는 첫 번째 요소의 형식으로 암시적으로 변환할 수 있어야 합니다. 여기서는 형식이 \n {1}이고 길이가 {0}인 튜플입니다. \n이 요소는 형식이 \n {3}이고 길이가 {2}인 튜플입니다. \n + + The attribute {0} is only meant for discriminated unions or record types. + The attribute {0} is only meant for discriminated unions or record types. + + - The attributes 'NoEquality', 'ReferenceEquality', 'StructuralEquality', 'NoComparison' and 'StructuralComparison' aren't meant to be used on adhoc classes, interfaces, structures, enums, delegates but only on discriminated unions or record types. - The attributes 'NoEquality', 'ReferenceEquality', 'StructuralEquality', 'NoComparison' and 'StructuralComparison' aren't meant to be used on adhoc classes, interfaces, structures, enums, delegates but only on discriminated unions or record types. + The attributes {0} are only meant for discriminated unions or record types. + The attributes {0} are only meant for discriminated unions or record types. diff --git a/src/Compiler/xlf/FSComp.txt.pl.xlf b/src/Compiler/xlf/FSComp.txt.pl.xlf index 4b945dc01f8..296b35dc403 100644 --- a/src/Compiler/xlf/FSComp.txt.pl.xlf +++ b/src/Compiler/xlf/FSComp.txt.pl.xlf @@ -12,9 +12,14 @@ Wszystkie elementy tablicy muszą być niejawnie konwertowalne na typ pierwszego elementu, który w tym miejscu jest krotką o długości {0} typu\n {1} \nTen element jest krotką o długości {2} typu\n {3} \n + + The attribute {0} is only meant for discriminated unions or record types. + The attribute {0} is only meant for discriminated unions or record types. + + - The attributes 'NoEquality', 'ReferenceEquality', 'StructuralEquality', 'NoComparison' and 'StructuralComparison' aren't meant to be used on adhoc classes, interfaces, structures, enums, delegates but only on discriminated unions or record types. - The attributes 'NoEquality', 'ReferenceEquality', 'StructuralEquality', 'NoComparison' and 'StructuralComparison' aren't meant to be used on adhoc classes, interfaces, structures, enums, delegates but only on discriminated unions or record types. + The attributes {0} are only meant for discriminated unions or record types. + The attributes {0} are only meant for discriminated unions or record types. diff --git a/src/Compiler/xlf/FSComp.txt.pt-BR.xlf b/src/Compiler/xlf/FSComp.txt.pt-BR.xlf index 6fa8bdfc55a..517d030df9a 100644 --- a/src/Compiler/xlf/FSComp.txt.pt-BR.xlf +++ b/src/Compiler/xlf/FSComp.txt.pt-BR.xlf @@ -12,9 +12,14 @@ Todos os elementos de uma matriz devem ser implicitamente conversíveis ao tipo do primeiro elemento, que aqui é uma tupla de comprimento {0} do tipo\n {1} \nEste elemento é uma tupla de comprimento {2} do tipo\n {3} \n + + The attribute {0} is only meant for discriminated unions or record types. + The attribute {0} is only meant for discriminated unions or record types. + + - The attributes 'NoEquality', 'ReferenceEquality', 'StructuralEquality', 'NoComparison' and 'StructuralComparison' aren't meant to be used on adhoc classes, interfaces, structures, enums, delegates but only on discriminated unions or record types. - The attributes 'NoEquality', 'ReferenceEquality', 'StructuralEquality', 'NoComparison' and 'StructuralComparison' aren't meant to be used on adhoc classes, interfaces, structures, enums, delegates but only on discriminated unions or record types. + The attributes {0} are only meant for discriminated unions or record types. + The attributes {0} are only meant for discriminated unions or record types. diff --git a/src/Compiler/xlf/FSComp.txt.ru.xlf b/src/Compiler/xlf/FSComp.txt.ru.xlf index de897c0729c..71d5f94ddfd 100644 --- a/src/Compiler/xlf/FSComp.txt.ru.xlf +++ b/src/Compiler/xlf/FSComp.txt.ru.xlf @@ -12,9 +12,14 @@ Все элементы массива должны поддерживать неявное преобразование в тип первого элемента, который здесь является кортежем длиной {0} типа\n {1} \nЭтот элемент является кортежем длиной {2} типа\n {3} \n + + The attribute {0} is only meant for discriminated unions or record types. + The attribute {0} is only meant for discriminated unions or record types. + + - The attributes 'NoEquality', 'ReferenceEquality', 'StructuralEquality', 'NoComparison' and 'StructuralComparison' aren't meant to be used on adhoc classes, interfaces, structures, enums, delegates but only on discriminated unions or record types. - The attributes 'NoEquality', 'ReferenceEquality', 'StructuralEquality', 'NoComparison' and 'StructuralComparison' aren't meant to be used on adhoc classes, interfaces, structures, enums, delegates but only on discriminated unions or record types. + The attributes {0} are only meant for discriminated unions or record types. + The attributes {0} are only meant for discriminated unions or record types. diff --git a/src/Compiler/xlf/FSComp.txt.tr.xlf b/src/Compiler/xlf/FSComp.txt.tr.xlf index c61fd625ea5..ce50d90b68a 100644 --- a/src/Compiler/xlf/FSComp.txt.tr.xlf +++ b/src/Compiler/xlf/FSComp.txt.tr.xlf @@ -12,9 +12,14 @@ Bir dizinin tüm öğeleri örtük olarak ilk öğenin türüne dönüştürülebilir olmalıdır. Burada ilk öğe {0} uzunluğunda türü\n {1} \nolan bir demet. Bu öğe ise {2} uzunluğunda türü\n {3} \nolan bir demet. + + The attribute {0} is only meant for discriminated unions or record types. + The attribute {0} is only meant for discriminated unions or record types. + + - The attributes 'NoEquality', 'ReferenceEquality', 'StructuralEquality', 'NoComparison' and 'StructuralComparison' aren't meant to be used on adhoc classes, interfaces, structures, enums, delegates but only on discriminated unions or record types. - The attributes 'NoEquality', 'ReferenceEquality', 'StructuralEquality', 'NoComparison' and 'StructuralComparison' aren't meant to be used on adhoc classes, interfaces, structures, enums, delegates but only on discriminated unions or record types. + The attributes {0} are only meant for discriminated unions or record types. + The attributes {0} are only meant for discriminated unions or record types. diff --git a/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf b/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf index 353324ca950..4d99dc088f6 100644 --- a/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf +++ b/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf @@ -12,9 +12,14 @@ 数组的所有元素必须可隐式转换为第一个元素的类型,这是一个长度为 {0} 的类型的元组\n {1} \n此元素是长度为 {2} 类型的元组\n {3} \n + + The attribute {0} is only meant for discriminated unions or record types. + The attribute {0} is only meant for discriminated unions or record types. + + - The attributes 'NoEquality', 'ReferenceEquality', 'StructuralEquality', 'NoComparison' and 'StructuralComparison' aren't meant to be used on adhoc classes, interfaces, structures, enums, delegates but only on discriminated unions or record types. - The attributes 'NoEquality', 'ReferenceEquality', 'StructuralEquality', 'NoComparison' and 'StructuralComparison' aren't meant to be used on adhoc classes, interfaces, structures, enums, delegates but only on discriminated unions or record types. + The attributes {0} are only meant for discriminated unions or record types. + The attributes {0} are only meant for discriminated unions or record types. diff --git a/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf b/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf index 58620aef80f..35aa2eeb46e 100644 --- a/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf +++ b/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf @@ -12,9 +12,14 @@ 陣列的所有元素必須以隱含方式轉換成第一個元素的類型,這是類型為\n {1} \n的元組長度 {0}此元素是類型為\n {3} \n的元組長度{2} + + The attribute {0} is only meant for discriminated unions or record types. + The attribute {0} is only meant for discriminated unions or record types. + + - The attributes 'NoEquality', 'ReferenceEquality', 'StructuralEquality', 'NoComparison' and 'StructuralComparison' aren't meant to be used on adhoc classes, interfaces, structures, enums, delegates but only on discriminated unions or record types. - The attributes 'NoEquality', 'ReferenceEquality', 'StructuralEquality', 'NoComparison' and 'StructuralComparison' aren't meant to be used on adhoc classes, interfaces, structures, enums, delegates but only on discriminated unions or record types. + The attributes {0} are only meant for discriminated unions or record types. + The attributes {0} are only meant for discriminated unions or record types. diff --git a/tests/FSharp.Compiler.ComponentTests/ErrorMessages/TypeAugmentationAttributes/TypeAugmentationAttributesTests.fs b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/TypeAugmentationAttributes/TypeAugmentationAttributesTests.fs new file mode 100644 index 00000000000..3994417766d --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/TypeAugmentationAttributes/TypeAugmentationAttributesTests.fs @@ -0,0 +1,12 @@ +module FSharp.Compiler.ComponentTests.ErrorMessages.TypeAugmentationAttributes +open Xunit +open FSharp.Test +open FSharp.Test.Compiler + +[] +let ``attributes on non OK types`` compilation = + compilation + |> asFsx + |> verifyBaselines + |> compile + |> shouldFail \ No newline at end of file diff --git a/tests/FSharp.Compiler.ComponentTests/ErrorMessages/TypeAugmentationAttributes/attributes.on.nonok.types.fsx b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/TypeAugmentationAttributes/attributes.on.nonok.types.fsx new file mode 100644 index 00000000000..82304c4caf2 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/TypeAugmentationAttributes/attributes.on.nonok.types.fsx @@ -0,0 +1,32 @@ +[] +type T1() = + override _.Equals _ = true +[] +type T2() = + override _.Equals _ = true +[] +type S1(a:int) = struct + override _.Equals _ = true +end +[] +type S2(a:int) = struct + override _.Equals _ = true +end +[] +type I1 = interface end +[] +type I2 = interface end +[] +type E1 = A = 1 | B = 2 +[] +type E2 = A = 1 | B = 2 +[] +type D1 = delegate of (int * int) -> int +[] +type D2 = delegate of (int * int) -> int +[] +module M1 = + let a = 1 +[] +module M2 = + let a = 1 diff --git a/tests/FSharp.Compiler.ComponentTests/ErrorMessages/TypeAugmentationAttributes/attributes.on.nonok.types.fsx.err.bsl b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/TypeAugmentationAttributes/attributes.on.nonok.types.fsx.err.bsl new file mode 100644 index 00000000000..2f1180f35ec --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/TypeAugmentationAttributes/attributes.on.nonok.types.fsx.err.bsl @@ -0,0 +1,25 @@ +attributes.on.nonok.types.fsx (2,6)-(2,8) typecheck error The attribute CustomEqualityAttribute is only meant for discriminated unions or record types. +attributes.on.nonok.types.fsx (2,6)-(2,8) typecheck warning The struct, record or union type 'T1' has an explicit implementation of 'Object.Equals'. Consider implementing a matching override for 'Object.GetHashCode()' +attributes.on.nonok.types.fsx (5,6)-(5,8) typecheck error The attributes CustomEqualityAttribute, CustomComparisonAttribute are only meant for discriminated unions or record types. +attributes.on.nonok.types.fsx (5,6)-(5,8) typecheck error A type with attribute 'CustomComparison' must have an explicit implementation of at least one of 'System.IComparable' or 'System.Collections.IStructuralComparable' +attributes.on.nonok.types.fsx (5,6)-(5,8) typecheck warning The struct, record or union type 'T2' has an explicit implementation of 'Object.Equals'. Consider implementing a matching override for 'Object.GetHashCode()' +attributes.on.nonok.types.fsx (8,6)-(8,8) typecheck error The 'CustomEquality' attribute must be used in conjunction with the 'NoComparison' or 'CustomComparison' attributes +attributes.on.nonok.types.fsx (8,6)-(8,8) typecheck warning The struct, record or union type 'S1' has an explicit implementation of 'Object.Equals'. Consider implementing a matching override for 'Object.GetHashCode()' +attributes.on.nonok.types.fsx (12,6)-(12,8) typecheck error A type with attribute 'CustomComparison' must have an explicit implementation of at least one of 'System.IComparable' or 'System.Collections.IStructuralComparable' +attributes.on.nonok.types.fsx (12,6)-(12,8) typecheck warning The struct, record or union type 'S2' has an explicit implementation of 'Object.Equals'. Consider implementing a matching override for 'Object.GetHashCode()' +attributes.on.nonok.types.fsx (16,6)-(16,8) typecheck error The attribute CustomEqualityAttribute is only meant for discriminated unions or record types. +attributes.on.nonok.types.fsx (16,6)-(16,8) typecheck error A type with attribute 'CustomEquality' must have an explicit implementation of at least one of 'Object.Equals(obj)', 'System.IEquatable<_>' or 'System.Collections.IStructuralEquatable' +attributes.on.nonok.types.fsx (18,6)-(18,8) typecheck error The attributes CustomEqualityAttribute, CustomComparisonAttribute are only meant for discriminated unions or record types. +attributes.on.nonok.types.fsx (18,6)-(18,8) typecheck error A type with attribute 'CustomEquality' must have an explicit implementation of at least one of 'Object.Equals(obj)', 'System.IEquatable<_>' or 'System.Collections.IStructuralEquatable' +attributes.on.nonok.types.fsx (20,6)-(20,8) typecheck error The attribute CustomEqualityAttribute is only meant for discriminated unions or record types. +attributes.on.nonok.types.fsx (20,6)-(20,8) typecheck error A type with attribute 'CustomEquality' must have an explicit implementation of at least one of 'Object.Equals(obj)', 'System.IEquatable<_>' or 'System.Collections.IStructuralEquatable' +attributes.on.nonok.types.fsx (22,6)-(22,8) typecheck error The attributes CustomEqualityAttribute, CustomComparisonAttribute are only meant for discriminated unions or record types. +attributes.on.nonok.types.fsx (22,6)-(22,8) typecheck error A type with attribute 'CustomEquality' must have an explicit implementation of at least one of 'Object.Equals(obj)', 'System.IEquatable<_>' or 'System.Collections.IStructuralEquatable' +attributes.on.nonok.types.fsx (24,6)-(24,8) typecheck error The attribute CustomEqualityAttribute is only meant for discriminated unions or record types. +attributes.on.nonok.types.fsx (24,6)-(24,8) typecheck error A type with attribute 'CustomEquality' must have an explicit implementation of at least one of 'Object.Equals(obj)', 'System.IEquatable<_>' or 'System.Collections.IStructuralEquatable' +attributes.on.nonok.types.fsx (26,6)-(26,8) typecheck error The attributes CustomEqualityAttribute, CustomComparisonAttribute are only meant for discriminated unions or record types. +attributes.on.nonok.types.fsx (26,6)-(26,8) typecheck error A type with attribute 'CustomEquality' must have an explicit implementation of at least one of 'Object.Equals(obj)', 'System.IEquatable<_>' or 'System.Collections.IStructuralEquatable' +attributes.on.nonok.types.fsx (28,8)-(28,10) typecheck error This type uses an invalid mix of the attributes 'NoEquality', 'ReferenceEquality', 'StructuralEquality', 'NoComparison' and 'StructuralComparison' +attributes.on.nonok.types.fsx (28,8)-(28,10) typecheck error A type with attribute 'CustomEquality' must have an explicit implementation of at least one of 'Object.Equals(obj)', 'System.IEquatable<_>' or 'System.Collections.IStructuralEquatable' +attributes.on.nonok.types.fsx (31,8)-(31,10) typecheck error This type uses an invalid mix of the attributes 'NoEquality', 'ReferenceEquality', 'StructuralEquality', 'NoComparison' and 'StructuralComparison' +attributes.on.nonok.types.fsx (31,8)-(31,10) typecheck error A type with attribute 'CustomEquality' must have an explicit implementation of at least one of 'Object.Equals(obj)', 'System.IEquatable<_>' or 'System.Collections.IStructuralEquatable' \ No newline at end of file diff --git a/tests/FSharp.Compiler.ComponentTests/ErrorMessages/TypeAugmentationAttributes/attributes.on.nonok.types.fsx.il.bsl b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/TypeAugmentationAttributes/attributes.on.nonok.types.fsx.il.bsl new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj b/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj index a9dd5382893..4665e67744e 100644 --- a/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj +++ b/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj @@ -166,9 +166,11 @@ + + - +