Skip to content

Separator between member and type annotation interpreted as operator #15923

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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