From 532b542212b673ce3e0113b9615767393b08e03b Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Thu, 9 Apr 2026 21:25:33 +0200 Subject: [PATCH] Add regression tests for #10043: backtick, @, and ! in type annotations Verifies that type annotations with invalid characters produce clear error messages: - backtick: FS3563 'This is not a valid identifier' - at sign: FS0615 'Unexpected infix operator in type expression' - bang: FS1141 'Identifiers followed by ! are reserved for future use' Fixes #10043 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../DiagnosticRegressionTests.fs | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/tests/FSharp.Compiler.ComponentTests/ErrorMessages/DiagnosticRegressionTests.fs b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/DiagnosticRegressionTests.fs index 36e258e4dd1..7310f83dbd1 100644 --- a/tests/FSharp.Compiler.ComponentTests/ErrorMessages/DiagnosticRegressionTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/DiagnosticRegressionTests.fs @@ -50,6 +50,43 @@ type Vehicle() = class end [ (Error 39, Line 3, Col 14, Line 3, Col 28, "The type 'OutOfScopeType' is not defined.") (Error 267, Line 3, Col 7, Line 3, Col 29, "This is not a valid constant expression or custom attribute value") ] +// https://github.com/dotnet/fsharp/issues/10043 +[] +let ``Issue 10043 - backtick in type annotation should not report unexpected keyword`` () = + FSharp + """ +let i:float`1 = 3.0 + """ + |> typecheck + |> shouldFail + |> withDiagnostics + [ (Error 3563, Line 2, Col 12, Line 2, Col 13, "This is not a valid identifier") + (Error 10, Line 2, Col 13, Line 2, Col 14, "Unexpected integer literal in binding. Expected '=' or other token.") ] + +// https://github.com/dotnet/fsharp/issues/10043 +[] +let ``Issue 10043 - at sign in type annotation should report infix operator`` () = + FSharp + """ +let i:float@1 = 3.0 + """ + |> typecheck + |> shouldFail + |> withDiagnostics + [ (Error 615, Line 2, Col 12, Line 2, Col 13, "Unexpected infix operator in type expression") ] + +// https://github.com/dotnet/fsharp/issues/10043 +[] +let ``Issue 10043 - bang in type annotation should report reserved identifier`` () = + FSharp + """ +let i:float!1 = 3.0 + """ + |> typecheck + |> shouldFail + |> withDiagnostics + [ (Error 1141, Line 2, Col 7, Line 2, Col 13, "Identifiers followed by '!' are reserved for future use") + (Error 10, Line 2, Col 13, Line 2, Col 14, "Unexpected integer literal in binding. Expected '=' or other token.") ] // https://github.com/dotnet/fsharp/issues/7177 []