Skip to content

Commit 1c0ba9f

Browse files
authored
Separator between member and type annotation interpreted as operator (#15923)
* Separator between member and type annotation interpreted as operator
1 parent 4061c38 commit 1c0ba9f

File tree

6 files changed

+33
-3
lines changed

6 files changed

+33
-3
lines changed

src/Compiler/Checking/CheckDeclarations.fs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,6 @@ module MutRecShapes =
178178

179179
let iterTyconsWithEnv f1 env xs = iterWithEnv f1 (fun _env _x -> ()) (fun _env _x -> ()) (fun _env _x -> ()) env xs
180180

181-
182181
/// Indicates a declaration is contained in the given module
183182
let ModuleOrNamespaceContainerInfo modref =
184183
ContainerInfo(Parent modref, Some(MemberOrValContainerInfo(modref, None, None, NoSafeInitInfo, [])))

src/Compiler/SyntaxTree/LexFilter.fs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,6 +1172,11 @@ type LexFilterImpl (
11721172
delayToken (pool.UseShiftedLocation(tokenTup, INFIX_AT_HAT_OP "^", 1, 0))
11731173
delayToken (pool.UseShiftedLocation(tokenTup, LESS res, 0, -1))
11741174
pool.Return tokenTup
1175+
1176+
| INFIX_COMPARE_OP ">:" ->
1177+
delayToken (pool.UseShiftedLocation(tokenTup, COLON, 1, 0))
1178+
delayToken (pool.UseShiftedLocation(tokenTup, GREATER res, 0, -1))
1179+
pool.Return tokenTup
11751180
// NOTE: this is "<@"
11761181
| LQUOTE ("<@ @>", false) ->
11771182
delayToken (pool.UseShiftedLocation(tokenTup, INFIX_AT_HAT_OP "@", 1, 0))

src/Compiler/lex.fsl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ let checkExprOp (lexbuf:UnicodeLexing.Lexbuf) =
112112
deprecatedWithError (FSComp.SR.lexCharNotAllowedInOperatorNames(":")) lexbuf.LexemeRange
113113
if lexbuf.LexemeContains '$' then
114114
deprecatedWithError (FSComp.SR.lexCharNotAllowedInOperatorNames("$")) lexbuf.LexemeRange
115+
116+
let checkExprGreaterColonOp (lexbuf:UnicodeLexing.Lexbuf) =
117+
if lexbuf.LexemeContains '$' then
118+
deprecatedWithError (FSComp.SR.lexCharNotAllowedInOperatorNames("$")) lexbuf.LexemeRange
115119

116120
let unexpectedChar lexbuf =
117121
LEX_FAILURE (FSComp.SR.lexUnexpectedChar(lexeme lexbuf))
@@ -945,7 +949,9 @@ rule token (args: LexArgs) (skip: bool) = parse
945949

946950
| ignored_op_char* ('@'|'^') op_char* { checkExprOp lexbuf; INFIX_AT_HAT_OP(lexeme lexbuf) }
947951

948-
| ignored_op_char* ('=' | "!=" | '<' | '>' | '$') op_char* { checkExprOp lexbuf; INFIX_COMPARE_OP(lexeme lexbuf) }
952+
| ignored_op_char* ('=' | "!=" | '<' | '$') op_char* { checkExprOp lexbuf; INFIX_COMPARE_OP(lexeme lexbuf) }
953+
954+
| ignored_op_char* ('>') op_char* { checkExprGreaterColonOp lexbuf; INFIX_COMPARE_OP(lexeme lexbuf) }
949955

950956
| ignored_op_char* ('&') op_char* { checkExprOp lexbuf; INFIX_AMP_OP(lexeme lexbuf) }
951957

tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/OperatorNames/BasicOperatorNames.fs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@ if !10 <> 3628800 then failwith "Failed: : 1"
1414
// Binary
1515
let (<<<) x y = x - x * y
1616
if 10 <<< 3 <> -20 then failwith "Failed: : 2"
17+
18+
let (>:) x y = x + x * y

tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/OperatorNames/OperatorNames.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,4 @@ module OperatorNames =
7373
|> asExe
7474
|> withOptions ["--warnaserror+"; "--nowarn:3370"; "--nowarn:988"]
7575
|> compileExeAndRun
76-
|> shouldSucceed
76+
|> shouldSucceed

tests/FSharp.Compiler.ComponentTests/ErrorMessages/ClassesTests.fs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,4 +686,22 @@ type X =
686686
app
687687
|> withLangVersion80
688688
|> compile
689+
|> shouldSucceed
690+
691+
[<Fact>]
692+
let ``No separator between member and type annotation`` () =
693+
FSharp """
694+
type IFoo<'T> =
695+
abstract member Bar<'T>: string -> unit
696+
"""
697+
|> typecheck
698+
|> shouldSucceed
699+
700+
[<Fact>]
701+
let ``Separator between member and type annotation`` () =
702+
FSharp """
703+
type IFoo<'T> =
704+
abstract member Bar<'T> : string -> unit
705+
"""
706+
|> typecheck
689707
|> shouldSucceed

0 commit comments

Comments
 (0)