Skip to content

Commit f498636

Browse files
T-GroCopilot
andcommitted
Add regression tests for #10043: backtick, @, and ! in type annotations
Tests that invalid characters in type annotation positions produce clear error messages instead of confusing 'Unexpected reserved keyword': - backtick: FS3563 'This is not a valid identifier' - @: FS0615 'Unexpected infix operator in type expression' Also removes deleted flaterrors.fs reference from fsproj. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent d04f46f commit f498636

3 files changed

Lines changed: 43 additions & 74 deletions

File tree

tests/FSharp.Compiler.ComponentTests/CompilerOptions/fsc/flaterrors.fs

Lines changed: 0 additions & 73 deletions
This file was deleted.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
module ErrorMessages.DiagnosticRegressionTests
2+
3+
open Xunit
4+
open FSharp.Test.Compiler
5+
6+
// https://github.com/dotnet/fsharp/issues/10043
7+
[<Fact>]
8+
let ``Issue 10043 - backtick in type annotation should not report unexpected keyword`` () =
9+
FSharp
10+
"""
11+
let i:float`1 = 3.0
12+
"""
13+
|> typecheck
14+
|> shouldFail
15+
|> withDiagnostics
16+
[ (Error 3563, Line 2, Col 12, Line 2, Col 13, "This is not a valid identifier")
17+
(Error 10, Line 2, Col 13, Line 2, Col 14, "Unexpected integer literal in binding. Expected '=' or other token.") ]
18+
19+
// https://github.com/dotnet/fsharp/issues/10043
20+
[<Fact>]
21+
let ``Issue 10043 - at sign in type annotation should report infix operator`` () =
22+
FSharp
23+
"""
24+
let i:float@1 = 3.0
25+
"""
26+
|> typecheck
27+
|> shouldFail
28+
|> withDiagnostics
29+
[ (Error 615, Line 2, Col 12, Line 2, Col 13, "Unexpected infix operator in type expression") ]
30+
31+
// https://github.com/dotnet/fsharp/issues/10043
32+
[<Fact>]
33+
let ``Issue 10043 - bang in type annotation should report reserved identifier`` () =
34+
FSharp
35+
"""
36+
let i:float!1 = 3.0
37+
"""
38+
|> typecheck
39+
|> shouldFail
40+
|> withDiagnostics
41+
[ (Error 1141, Line 2, Col 7, Line 2, Col 13, "Identifiers followed by '!' are reserved for future use")
42+
(Error 10, Line 2, Col 13, Line 2, Col 14, "Unexpected integer literal in binding. Expected '=' or other token.") ]

tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@
300300
<Compile Include="ErrorMessages\MissingElseBranch.fs" />
301301
<Compile Include="ErrorMessages\MissingExpressionTests.fs" />
302302
<Compile Include="ErrorMessages\ModuleTests.fs" />
303+
<Compile Include="ErrorMessages\DiagnosticRegressionTests.fs" />
303304
<Compile Include="ErrorMessages\NameResolutionTests.fs" />
304305
<Compile Include="ErrorMessages\SuggestionsTests.fs" />
305306
<Compile Include="ErrorMessages\TypeMismatchTests.fs" />
@@ -395,7 +396,6 @@
395396
<Compile Include="CompilerOptions\fsc\crossoptimize.fs" />
396397
<Compile Include="CompilerOptions\fsc\debug.fs" />
397398
<Compile Include="CompilerOptions\fsc\disableLanguageFeature.fs" />
398-
<Compile Include="CompilerOptions\fsc\flaterrors.fs" />
399399
<Compile Include="CompilerOptions\fsc\FscOptionTests.fs" />
400400
<Compile Include="CompilerOptions\fsc\determinism\determinism.fs" />
401401
<Compile Include="CompilerOptions\fsc\highentropyva.fs" />

0 commit comments

Comments
 (0)