From 94885f55a30961d4fd1f2dd95786060036d65c13 Mon Sep 17 00:00:00 2001 From: Erik Schierboom Date: Wed, 30 Dec 2020 04:45:36 +0100 Subject: [PATCH] Raise error when using active pattern in literal binding (#10816) --- src/fsharp/CheckExpressions.fs | 3 +++ src/fsharp/FSComp.txt | 1 + src/fsharp/xlf/FSComp.txt.cs.xlf | 5 +++++ src/fsharp/xlf/FSComp.txt.de.xlf | 5 +++++ src/fsharp/xlf/FSComp.txt.es.xlf | 5 +++++ src/fsharp/xlf/FSComp.txt.fr.xlf | 5 +++++ src/fsharp/xlf/FSComp.txt.it.xlf | 5 +++++ src/fsharp/xlf/FSComp.txt.ja.xlf | 5 +++++ src/fsharp/xlf/FSComp.txt.ko.xlf | 5 +++++ src/fsharp/xlf/FSComp.txt.pl.xlf | 5 +++++ src/fsharp/xlf/FSComp.txt.pt-BR.xlf | 5 +++++ src/fsharp/xlf/FSComp.txt.ru.xlf | 5 +++++ src/fsharp/xlf/FSComp.txt.tr.xlf | 5 +++++ src/fsharp/xlf/FSComp.txt.zh-Hans.xlf | 5 +++++ src/fsharp/xlf/FSComp.txt.zh-Hant.xlf | 5 +++++ .../ErrorMessages/InvalidLiteralTests.fs | 18 ++++++++++++++++++ .../FSharp.Compiler.ComponentTests.fsproj | 3 ++- 17 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 tests/FSharp.Compiler.ComponentTests/ErrorMessages/InvalidLiteralTests.fs diff --git a/src/fsharp/CheckExpressions.fs b/src/fsharp/CheckExpressions.fs index 423e26a98..b30ae9cd3 100644 --- a/src/fsharp/CheckExpressions.fs +++ b/src/fsharp/CheckExpressions.fs @@ -9755,6 +9755,9 @@ and TcLetBinding cenv isUse env containerInfo declKind tpenv (synBinds, synBinds | _ when inlineFlag.MustInline -> error(Error(FSComp.SR.tcInvalidInlineSpecification(), m)) + | TPat_query _ when HasFSharpAttribute cenv.g cenv.g.attrib_LiteralAttribute attrs -> + error(Error(FSComp.SR.tcLiteralAttributeCannotUseActivePattern(), m)) + | _ -> let tmp, _ = mkCompGenLocal m "patternInput" (generalizedTypars +-> tauTy) diff --git a/src/fsharp/FSComp.txt b/src/fsharp/FSComp.txt index 828dda792..35001aedf 100644 --- a/src/fsharp/FSComp.txt +++ b/src/fsharp/FSComp.txt @@ -1552,3 +1552,4 @@ forFormatInvalidForInterpolated4,"Interpolated strings used as type IFormattable 3390,xmlDocDuplicateParameter,"This XML comment is invalid: multiple documentation entries for parameter '%s'" 3390,xmlDocUnresolvedCrossReference,"This XML comment is invalid: unresolved cross-reference '%s'" 3390,xmlDocMissingParameter,"This XML comment is incomplete: no documentation for parameter '%s'" +3391,tcLiteralAttributeCannotUseActivePattern,"A [] declaration cannot use an active pattern for its identifier" \ No newline at end of file diff --git a/src/fsharp/xlf/FSComp.txt.cs.xlf b/src/fsharp/xlf/FSComp.txt.cs.xlf index 9a39a4c95..44619c850 100644 --- a/src/fsharp/xlf/FSComp.txt.cs.xlf +++ b/src/fsharp/xlf/FSComp.txt.cs.xlf @@ -367,6 +367,11 @@ use! se nedá kombinovat s and!. + + A [<Literal>] declaration cannot use an active pattern for its identifier + A [<Literal>] declaration cannot use an active pattern for its identifier + + Cannot assign a value to another value marked literal Hodnota se nedá přiřadit k jiné hodnotě, která je označená jako literál. diff --git a/src/fsharp/xlf/FSComp.txt.de.xlf b/src/fsharp/xlf/FSComp.txt.de.xlf index 7f61d7dc8..3f079a1f8 100644 --- a/src/fsharp/xlf/FSComp.txt.de.xlf +++ b/src/fsharp/xlf/FSComp.txt.de.xlf @@ -367,6 +367,11 @@ "use!" darf nicht mit "and!" kombiniert werden. + + A [<Literal>] declaration cannot use an active pattern for its identifier + A [<Literal>] declaration cannot use an active pattern for its identifier + + Cannot assign a value to another value marked literal Ein Wert kann keinem anderen als Literal markierten Wert zugewiesen werden. diff --git a/src/fsharp/xlf/FSComp.txt.es.xlf b/src/fsharp/xlf/FSComp.txt.es.xlf index 3c4a43eab..2e5cc7e0a 100644 --- a/src/fsharp/xlf/FSComp.txt.es.xlf +++ b/src/fsharp/xlf/FSComp.txt.es.xlf @@ -367,6 +367,11 @@ No se puede combinar use! con and! + + A [<Literal>] declaration cannot use an active pattern for its identifier + A [<Literal>] declaration cannot use an active pattern for its identifier + + Cannot assign a value to another value marked literal No se puede asignar un valor a otro marcado como literal diff --git a/src/fsharp/xlf/FSComp.txt.fr.xlf b/src/fsharp/xlf/FSComp.txt.fr.xlf index 5adced0a9..08c7d6e91 100644 --- a/src/fsharp/xlf/FSComp.txt.fr.xlf +++ b/src/fsharp/xlf/FSComp.txt.fr.xlf @@ -367,6 +367,11 @@ use! ne peut pas être combiné avec and! + + A [<Literal>] declaration cannot use an active pattern for its identifier + A [<Literal>] declaration cannot use an active pattern for its identifier + + Cannot assign a value to another value marked literal Impossible d'affecter une valeur à une autre valeur marquée comme littérale diff --git a/src/fsharp/xlf/FSComp.txt.it.xlf b/src/fsharp/xlf/FSComp.txt.it.xlf index 3d0386944..9ac812b24 100644 --- a/src/fsharp/xlf/FSComp.txt.it.xlf +++ b/src/fsharp/xlf/FSComp.txt.it.xlf @@ -367,6 +367,11 @@ Non è possibile combinare use! con and! + + A [<Literal>] declaration cannot use an active pattern for its identifier + A [<Literal>] declaration cannot use an active pattern for its identifier + + Cannot assign a value to another value marked literal Non è possibile assegnare un valore a un altro valore contrassegnato come letterale diff --git a/src/fsharp/xlf/FSComp.txt.ja.xlf b/src/fsharp/xlf/FSComp.txt.ja.xlf index c6de2f62a..5a62f6c6e 100644 --- a/src/fsharp/xlf/FSComp.txt.ja.xlf +++ b/src/fsharp/xlf/FSComp.txt.ja.xlf @@ -367,6 +367,11 @@ use! を and! と組み合わせて使用することはできません + + A [<Literal>] declaration cannot use an active pattern for its identifier + A [<Literal>] declaration cannot use an active pattern for its identifier + + Cannot assign a value to another value marked literal リテラルとしてマークされた別の値に値を割り当てることはできません diff --git a/src/fsharp/xlf/FSComp.txt.ko.xlf b/src/fsharp/xlf/FSComp.txt.ko.xlf index 94811a157..35dddbb2d 100644 --- a/src/fsharp/xlf/FSComp.txt.ko.xlf +++ b/src/fsharp/xlf/FSComp.txt.ko.xlf @@ -367,6 +367,11 @@ use!는 and!와 함께 사용할 수 없습니다. + + A [<Literal>] declaration cannot use an active pattern for its identifier + A [<Literal>] declaration cannot use an active pattern for its identifier + + Cannot assign a value to another value marked literal 리터럴로 표시된 다른 값에 값을 할당할 수 없습니다. diff --git a/src/fsharp/xlf/FSComp.txt.pl.xlf b/src/fsharp/xlf/FSComp.txt.pl.xlf index 80d8dbcb5..ca4efcfb3 100644 --- a/src/fsharp/xlf/FSComp.txt.pl.xlf +++ b/src/fsharp/xlf/FSComp.txt.pl.xlf @@ -367,6 +367,11 @@ Elementu use! nie można łączyć z elementem and! + + A [<Literal>] declaration cannot use an active pattern for its identifier + A [<Literal>] declaration cannot use an active pattern for its identifier + + Cannot assign a value to another value marked literal Nie można przypisać wartości do innej wartości oznaczonej jako literał diff --git a/src/fsharp/xlf/FSComp.txt.pt-BR.xlf b/src/fsharp/xlf/FSComp.txt.pt-BR.xlf index c6a77375b..49eff2cb7 100644 --- a/src/fsharp/xlf/FSComp.txt.pt-BR.xlf +++ b/src/fsharp/xlf/FSComp.txt.pt-BR.xlf @@ -367,6 +367,11 @@ use! não pode ser combinado com and! + + A [<Literal>] declaration cannot use an active pattern for its identifier + A [<Literal>] declaration cannot use an active pattern for its identifier + + Cannot assign a value to another value marked literal Não é possível atribuir um valor a outro valor marcado como literal diff --git a/src/fsharp/xlf/FSComp.txt.ru.xlf b/src/fsharp/xlf/FSComp.txt.ru.xlf index 3ccd9d1a9..bb1d6cc81 100644 --- a/src/fsharp/xlf/FSComp.txt.ru.xlf +++ b/src/fsharp/xlf/FSComp.txt.ru.xlf @@ -367,6 +367,11 @@ use! запрещено сочетать с and! + + A [<Literal>] declaration cannot use an active pattern for its identifier + A [<Literal>] declaration cannot use an active pattern for its identifier + + Cannot assign a value to another value marked literal Невозможно присвоить значение другому значению, помеченному как литерал diff --git a/src/fsharp/xlf/FSComp.txt.tr.xlf b/src/fsharp/xlf/FSComp.txt.tr.xlf index 6f29c319d..e07977495 100644 --- a/src/fsharp/xlf/FSComp.txt.tr.xlf +++ b/src/fsharp/xlf/FSComp.txt.tr.xlf @@ -367,6 +367,11 @@ use!, and! ile birleştirilemez + + A [<Literal>] declaration cannot use an active pattern for its identifier + A [<Literal>] declaration cannot use an active pattern for its identifier + + Cannot assign a value to another value marked literal Sabit değer olarak işaretlenen bir değere başka bir değer atanamaz diff --git a/src/fsharp/xlf/FSComp.txt.zh-Hans.xlf b/src/fsharp/xlf/FSComp.txt.zh-Hans.xlf index daf850cea..877a73a78 100644 --- a/src/fsharp/xlf/FSComp.txt.zh-Hans.xlf +++ b/src/fsharp/xlf/FSComp.txt.zh-Hans.xlf @@ -367,6 +367,11 @@ use! 不得与 and! 结合使用 + + A [<Literal>] declaration cannot use an active pattern for its identifier + A [<Literal>] declaration cannot use an active pattern for its identifier + + Cannot assign a value to another value marked literal 无法将值分配给标记为文本的其他值 diff --git a/src/fsharp/xlf/FSComp.txt.zh-Hant.xlf b/src/fsharp/xlf/FSComp.txt.zh-Hant.xlf index a466dbe4e..cc5228630 100644 --- a/src/fsharp/xlf/FSComp.txt.zh-Hant.xlf +++ b/src/fsharp/xlf/FSComp.txt.zh-Hant.xlf @@ -367,6 +367,11 @@ use! 不可與 and! 合併 + + A [<Literal>] declaration cannot use an active pattern for its identifier + A [<Literal>] declaration cannot use an active pattern for its identifier + + Cannot assign a value to another value marked literal 無法將值指派給標記為常值的其他值 diff --git a/tests/FSharp.Compiler.ComponentTests/ErrorMessages/InvalidLiteralTests.fs b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/InvalidLiteralTests.fs new file mode 100644 index 000000000..f3d62e974 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/InvalidLiteralTests.fs @@ -0,0 +1,18 @@ +// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. + +namespace FSharp.Compiler.ComponentTests.ErrorMessages + +open Xunit +open FSharp.Test.Utilities.Compiler + +module ``Invalid literals`` = + + [] + let ``Using Active Pattern``() = + FSharp """ +let (|A|) x = x + 1 +let [] (A x) = 1 + """ + |> typecheck + |> shouldFail + |> withSingleDiagnostic (Error 3391, Line 3, Col 17, Line 3, Col 22, "A [] declaration cannot use an active pattern for its identifier") diff --git a/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj b/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj index fb960abd3..62254811b 100644 --- a/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj +++ b/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj @@ -29,7 +29,8 @@ - + + -- GitLab