Skip to content

Commit

Permalink
Raise error when using active pattern in literal binding (#10816)
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikSchierboom authored Dec 30, 2020
1 parent 2338353 commit 94885f5
Show file tree
Hide file tree
Showing 17 changed files with 89 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/fsharp/CheckExpressions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/fsharp/FSComp.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 [<Literal>] declaration cannot use an active pattern for its identifier"
5 changes: 5 additions & 0 deletions src/fsharp/xlf/FSComp.txt.cs.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,11 @@
<target state="translated">use! se nedá kombinovat s and!.</target>
<note />
</trans-unit>
<trans-unit id="tcLiteralAttributeCannotUseActivePattern">
<source>A [&lt;Literal&gt;] declaration cannot use an active pattern for its identifier</source>
<target state="new">A [&lt;Literal&gt;] declaration cannot use an active pattern for its identifier</target>
<note />
</trans-unit>
<trans-unit id="tcLiteralFieldAssignmentNoArg">
<source>Cannot assign a value to another value marked literal</source>
<target state="translated">Hodnota se nedá přiřadit k jiné hodnotě, která je označená jako literál.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/fsharp/xlf/FSComp.txt.de.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,11 @@
<target state="translated">"use!" darf nicht mit "and!" kombiniert werden.</target>
<note />
</trans-unit>
<trans-unit id="tcLiteralAttributeCannotUseActivePattern">
<source>A [&lt;Literal&gt;] declaration cannot use an active pattern for its identifier</source>
<target state="new">A [&lt;Literal&gt;] declaration cannot use an active pattern for its identifier</target>
<note />
</trans-unit>
<trans-unit id="tcLiteralFieldAssignmentNoArg">
<source>Cannot assign a value to another value marked literal</source>
<target state="translated">Ein Wert kann keinem anderen als Literal markierten Wert zugewiesen werden.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/fsharp/xlf/FSComp.txt.es.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,11 @@
<target state="translated">No se puede combinar use! con and!</target>
<note />
</trans-unit>
<trans-unit id="tcLiteralAttributeCannotUseActivePattern">
<source>A [&lt;Literal&gt;] declaration cannot use an active pattern for its identifier</source>
<target state="new">A [&lt;Literal&gt;] declaration cannot use an active pattern for its identifier</target>
<note />
</trans-unit>
<trans-unit id="tcLiteralFieldAssignmentNoArg">
<source>Cannot assign a value to another value marked literal</source>
<target state="translated">No se puede asignar un valor a otro marcado como literal</target>
Expand Down
5 changes: 5 additions & 0 deletions src/fsharp/xlf/FSComp.txt.fr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,11 @@
<target state="translated">use! ne peut pas être combiné avec and!</target>
<note />
</trans-unit>
<trans-unit id="tcLiteralAttributeCannotUseActivePattern">
<source>A [&lt;Literal&gt;] declaration cannot use an active pattern for its identifier</source>
<target state="new">A [&lt;Literal&gt;] declaration cannot use an active pattern for its identifier</target>
<note />
</trans-unit>
<trans-unit id="tcLiteralFieldAssignmentNoArg">
<source>Cannot assign a value to another value marked literal</source>
<target state="translated">Impossible d'affecter une valeur à une autre valeur marquée comme littérale</target>
Expand Down
5 changes: 5 additions & 0 deletions src/fsharp/xlf/FSComp.txt.it.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,11 @@
<target state="translated">Non è possibile combinare use! con and!</target>
<note />
</trans-unit>
<trans-unit id="tcLiteralAttributeCannotUseActivePattern">
<source>A [&lt;Literal&gt;] declaration cannot use an active pattern for its identifier</source>
<target state="new">A [&lt;Literal&gt;] declaration cannot use an active pattern for its identifier</target>
<note />
</trans-unit>
<trans-unit id="tcLiteralFieldAssignmentNoArg">
<source>Cannot assign a value to another value marked literal</source>
<target state="translated">Non è possibile assegnare un valore a un altro valore contrassegnato come letterale</target>
Expand Down
5 changes: 5 additions & 0 deletions src/fsharp/xlf/FSComp.txt.ja.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,11 @@
<target state="translated">use! を and! と組み合わせて使用することはできません</target>
<note />
</trans-unit>
<trans-unit id="tcLiteralAttributeCannotUseActivePattern">
<source>A [&lt;Literal&gt;] declaration cannot use an active pattern for its identifier</source>
<target state="new">A [&lt;Literal&gt;] declaration cannot use an active pattern for its identifier</target>
<note />
</trans-unit>
<trans-unit id="tcLiteralFieldAssignmentNoArg">
<source>Cannot assign a value to another value marked literal</source>
<target state="translated">リテラルとしてマークされた別の値に値を割り当てることはできません</target>
Expand Down
5 changes: 5 additions & 0 deletions src/fsharp/xlf/FSComp.txt.ko.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,11 @@
<target state="translated">use!는 and!와 함께 사용할 수 없습니다.</target>
<note />
</trans-unit>
<trans-unit id="tcLiteralAttributeCannotUseActivePattern">
<source>A [&lt;Literal&gt;] declaration cannot use an active pattern for its identifier</source>
<target state="new">A [&lt;Literal&gt;] declaration cannot use an active pattern for its identifier</target>
<note />
</trans-unit>
<trans-unit id="tcLiteralFieldAssignmentNoArg">
<source>Cannot assign a value to another value marked literal</source>
<target state="translated">리터럴로 표시된 다른 값에 값을 할당할 수 없습니다.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/fsharp/xlf/FSComp.txt.pl.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,11 @@
<target state="translated">Elementu use! nie można łączyć z elementem and!</target>
<note />
</trans-unit>
<trans-unit id="tcLiteralAttributeCannotUseActivePattern">
<source>A [&lt;Literal&gt;] declaration cannot use an active pattern for its identifier</source>
<target state="new">A [&lt;Literal&gt;] declaration cannot use an active pattern for its identifier</target>
<note />
</trans-unit>
<trans-unit id="tcLiteralFieldAssignmentNoArg">
<source>Cannot assign a value to another value marked literal</source>
<target state="translated">Nie można przypisać wartości do innej wartości oznaczonej jako literał</target>
Expand Down
5 changes: 5 additions & 0 deletions src/fsharp/xlf/FSComp.txt.pt-BR.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,11 @@
<target state="translated">use! não pode ser combinado com and!</target>
<note />
</trans-unit>
<trans-unit id="tcLiteralAttributeCannotUseActivePattern">
<source>A [&lt;Literal&gt;] declaration cannot use an active pattern for its identifier</source>
<target state="new">A [&lt;Literal&gt;] declaration cannot use an active pattern for its identifier</target>
<note />
</trans-unit>
<trans-unit id="tcLiteralFieldAssignmentNoArg">
<source>Cannot assign a value to another value marked literal</source>
<target state="translated">Não é possível atribuir um valor a outro valor marcado como literal</target>
Expand Down
5 changes: 5 additions & 0 deletions src/fsharp/xlf/FSComp.txt.ru.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,11 @@
<target state="translated">use! запрещено сочетать с and!</target>
<note />
</trans-unit>
<trans-unit id="tcLiteralAttributeCannotUseActivePattern">
<source>A [&lt;Literal&gt;] declaration cannot use an active pattern for its identifier</source>
<target state="new">A [&lt;Literal&gt;] declaration cannot use an active pattern for its identifier</target>
<note />
</trans-unit>
<trans-unit id="tcLiteralFieldAssignmentNoArg">
<source>Cannot assign a value to another value marked literal</source>
<target state="translated">Невозможно присвоить значение другому значению, помеченному как литерал</target>
Expand Down
5 changes: 5 additions & 0 deletions src/fsharp/xlf/FSComp.txt.tr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,11 @@
<target state="translated">use!, and! ile birleştirilemez</target>
<note />
</trans-unit>
<trans-unit id="tcLiteralAttributeCannotUseActivePattern">
<source>A [&lt;Literal&gt;] declaration cannot use an active pattern for its identifier</source>
<target state="new">A [&lt;Literal&gt;] declaration cannot use an active pattern for its identifier</target>
<note />
</trans-unit>
<trans-unit id="tcLiteralFieldAssignmentNoArg">
<source>Cannot assign a value to another value marked literal</source>
<target state="translated">Sabit değer olarak işaretlenen bir değere başka bir değer atanamaz</target>
Expand Down
5 changes: 5 additions & 0 deletions src/fsharp/xlf/FSComp.txt.zh-Hans.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,11 @@
<target state="translated">use! 不得与 and! 结合使用</target>
<note />
</trans-unit>
<trans-unit id="tcLiteralAttributeCannotUseActivePattern">
<source>A [&lt;Literal&gt;] declaration cannot use an active pattern for its identifier</source>
<target state="new">A [&lt;Literal&gt;] declaration cannot use an active pattern for its identifier</target>
<note />
</trans-unit>
<trans-unit id="tcLiteralFieldAssignmentNoArg">
<source>Cannot assign a value to another value marked literal</source>
<target state="translated">无法将值分配给标记为文本的其他值</target>
Expand Down
5 changes: 5 additions & 0 deletions src/fsharp/xlf/FSComp.txt.zh-Hant.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,11 @@
<target state="translated">use! 不可與 and! 合併</target>
<note />
</trans-unit>
<trans-unit id="tcLiteralAttributeCannotUseActivePattern">
<source>A [&lt;Literal&gt;] declaration cannot use an active pattern for its identifier</source>
<target state="new">A [&lt;Literal&gt;] declaration cannot use an active pattern for its identifier</target>
<note />
</trans-unit>
<trans-unit id="tcLiteralFieldAssignmentNoArg">
<source>Cannot assign a value to another value marked literal</source>
<target state="translated">無法將值指派給標記為常值的其他值</target>
Expand Down
Original file line number Diff line number Diff line change
@@ -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`` =

[<Fact>]
let ``Using Active Pattern``() =
FSharp """
let (|A|) x = x + 1
let [<Literal>] (A x) = 1
"""
|> typecheck
|> shouldFail
|> withSingleDiagnostic (Error 3391, Line 3, Col 17, Line 3, Col 22, "A [<Literal>] declaration cannot use an active pattern for its identifier")
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
<Compile Include="ErrorMessages\ConstructorTests.fs" />
<Compile Include="ErrorMessages\DontSuggestTests.fs" />
<Compile Include="ErrorMessages\ElseBranchHasWrongTypeTests.fs" />
<Compile Include="ErrorMessages\InvalidNumericLiteralTests.fs" />
<Compile Include="ErrorMessages\InvalidLiteralTests.fs" />
<Compile Include="ErrorMessages\InvalidNumericLiteralTests.fs" />
<Compile Include="ErrorMessages\MissingElseBranch.fs" />
<Compile Include="ErrorMessages\MissingExpressionTests.fs" />
<Compile Include="ErrorMessages\ModuleAbbreviationTests.fs" />
Expand Down

0 comments on commit 94885f5

Please sign in to comment.