Skip to content

Commit

Permalink
Separator between member and type annotation interpreted as operator (d…
Browse files Browse the repository at this point in the history
…otnet#15923)

* Separator between member and type annotation interpreted as operator
  • Loading branch information
edgarfgp authored Oct 13, 2023
1 parent 4061c38 commit 1c0ba9f
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 3 deletions.
1 change: 0 additions & 1 deletion src/Compiler/Checking/CheckDeclarations.fs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ module MutRecShapes =

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


/// Indicates a declaration is contained in the given module
let ModuleOrNamespaceContainerInfo modref =
ContainerInfo(Parent modref, Some(MemberOrValContainerInfo(modref, None, None, NoSafeInitInfo, [])))
Expand Down
5 changes: 5 additions & 0 deletions src/Compiler/SyntaxTree/LexFilter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1172,6 +1172,11 @@ type LexFilterImpl (
delayToken (pool.UseShiftedLocation(tokenTup, INFIX_AT_HAT_OP "^", 1, 0))
delayToken (pool.UseShiftedLocation(tokenTup, LESS res, 0, -1))
pool.Return tokenTup

| INFIX_COMPARE_OP ">:" ->
delayToken (pool.UseShiftedLocation(tokenTup, COLON, 1, 0))
delayToken (pool.UseShiftedLocation(tokenTup, GREATER res, 0, -1))
pool.Return tokenTup
// NOTE: this is "<@"
| LQUOTE ("<@ @>", false) ->
delayToken (pool.UseShiftedLocation(tokenTup, INFIX_AT_HAT_OP "@", 1, 0))
Expand Down
8 changes: 7 additions & 1 deletion src/Compiler/lex.fsl
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ let checkExprOp (lexbuf:UnicodeLexing.Lexbuf) =
deprecatedWithError (FSComp.SR.lexCharNotAllowedInOperatorNames(":")) lexbuf.LexemeRange
if lexbuf.LexemeContains '$' then
deprecatedWithError (FSComp.SR.lexCharNotAllowedInOperatorNames("$")) lexbuf.LexemeRange

let checkExprGreaterColonOp (lexbuf:UnicodeLexing.Lexbuf) =
if lexbuf.LexemeContains '$' then
deprecatedWithError (FSComp.SR.lexCharNotAllowedInOperatorNames("$")) lexbuf.LexemeRange

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

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

| ignored_op_char* ('=' | "!=" | '<' | '>' | '$') op_char* { checkExprOp lexbuf; INFIX_COMPARE_OP(lexeme lexbuf) }
| ignored_op_char* ('=' | "!=" | '<' | '$') op_char* { checkExprOp lexbuf; INFIX_COMPARE_OP(lexeme lexbuf) }

| ignored_op_char* ('>') op_char* { checkExprGreaterColonOp lexbuf; INFIX_COMPARE_OP(lexeme lexbuf) }

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ if !10 <> 3628800 then failwith "Failed: : 1"
// Binary
let (<<<) x y = x - x * y
if 10 <<< 3 <> -20 then failwith "Failed: : 2"

let (>:) x y = x + x * y
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,4 @@ module OperatorNames =
|> asExe
|> withOptions ["--warnaserror+"; "--nowarn:3370"; "--nowarn:988"]
|> compileExeAndRun
|> shouldSucceed
|> shouldSucceed
18 changes: 18 additions & 0 deletions tests/FSharp.Compiler.ComponentTests/ErrorMessages/ClassesTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -686,4 +686,22 @@ type X =
app
|> withLangVersion80
|> compile
|> shouldSucceed

[<Fact>]
let ``No separator between member and type annotation`` () =
FSharp """
type IFoo<'T> =
abstract member Bar<'T>: string -> unit
"""
|> typecheck
|> shouldSucceed

[<Fact>]
let ``Separator between member and type annotation`` () =
FSharp """
type IFoo<'T> =
abstract member Bar<'T> : string -> unit
"""
|> typecheck
|> shouldSucceed

0 comments on commit 1c0ba9f

Please sign in to comment.