From 8d8e0bbec6224ab787b0c95ca1eef8ba06d4cd12 Mon Sep 17 00:00:00 2001 From: Edgar Gonzalez Date: Mon, 4 Sep 2023 17:29:55 +0200 Subject: [PATCH 1/6] Separator between member and type annotation interpreted as operator --- src/Compiler/SyntaxTree/LexFilter.fs | 5 +++++ src/Compiler/lex.fsl | 8 +++++++- .../UnionCasePatternMatchingErrors.fs | 18 ++++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/Compiler/SyntaxTree/LexFilter.fs b/src/Compiler/SyntaxTree/LexFilter.fs index 64bc43c6ebc..e592960c6ba 100644 --- a/src/Compiler/SyntaxTree/LexFilter.fs +++ b/src/Compiler/SyntaxTree/LexFilter.fs @@ -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)) diff --git a/src/Compiler/lex.fsl b/src/Compiler/lex.fsl index e8edd3086c1..bc2d65fce46 100644 --- a/src/Compiler/lex.fsl +++ b/src/Compiler/lex.fsl @@ -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 checkExprOp2 (lexbuf:UnicodeLexing.Lexbuf) = + if lexbuf.LexemeContains '$' then + deprecatedWithError (FSComp.SR.lexCharNotAllowedInOperatorNames("$")) lexbuf.LexemeRange let unexpectedChar lexbuf = LEX_FAILURE (FSComp.SR.lexUnexpectedChar(lexeme lexbuf)) @@ -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* { checkExprOp2 lexbuf; INFIX_COMPARE_OP(lexeme lexbuf) } | ignored_op_char* ('&') op_char* { checkExprOp lexbuf; INFIX_AMP_OP(lexeme lexbuf) } diff --git a/tests/FSharp.Compiler.ComponentTests/ErrorMessages/UnionCasePatternMatchingErrors.fs b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/UnionCasePatternMatchingErrors.fs index df94ca89e0e..53e537e2d23 100644 --- a/tests/FSharp.Compiler.ComponentTests/ErrorMessages/UnionCasePatternMatchingErrors.fs +++ b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/UnionCasePatternMatchingErrors.fs @@ -245,6 +245,24 @@ let myVal = (Warning 3548, Line 17, Col 20, Line 17, Col 23, "Pattern discard is not allowed for union case that takes no data.") ] +[] +let ``Separator between member and type annotation interpreted as operator`` () = + FSharp """ +type IFoo<'T> = + abstract member Bar<'T>: string -> unit + """ + |> typecheck + |> shouldSucceed + +[] +let ``Separator between member and type annotation interpreted as operator 2`` () = + FSharp """ +type IFoo<'T> = + abstract member Bar<'T> : string -> unit + """ + |> typecheck + |> shouldSucceed + [] let ``Multiple pattern discards not allowed for union case that takes no data with Lang 7`` () = FSharp """ From a904ddc715f37da835cada5b70379ec52faecda7 Mon Sep 17 00:00:00 2001 From: Edgar Gonzalez Date: Tue, 5 Sep 2023 10:40:57 +0200 Subject: [PATCH 2/6] more testing --- src/Compiler/lex.fsl | 4 ++-- .../ErrorMessages/UnionCasePatternMatchingErrors.fs | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Compiler/lex.fsl b/src/Compiler/lex.fsl index bc2d65fce46..b3ddfad4a13 100644 --- a/src/Compiler/lex.fsl +++ b/src/Compiler/lex.fsl @@ -113,7 +113,7 @@ let checkExprOp (lexbuf:UnicodeLexing.Lexbuf) = if lexbuf.LexemeContains '$' then deprecatedWithError (FSComp.SR.lexCharNotAllowedInOperatorNames("$")) lexbuf.LexemeRange -let checkExprOp2 (lexbuf:UnicodeLexing.Lexbuf) = +let checkExprGreaterColonOp (lexbuf:UnicodeLexing.Lexbuf) = if lexbuf.LexemeContains '$' then deprecatedWithError (FSComp.SR.lexCharNotAllowedInOperatorNames("$")) lexbuf.LexemeRange @@ -951,7 +951,7 @@ rule token (args: LexArgs) (skip: bool) = parse | ignored_op_char* ('=' | "!=" | '<' | '$') op_char* { checkExprOp lexbuf; INFIX_COMPARE_OP(lexeme lexbuf) } - | ignored_op_char* ('>') op_char* { checkExprOp2 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) } diff --git a/tests/FSharp.Compiler.ComponentTests/ErrorMessages/UnionCasePatternMatchingErrors.fs b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/UnionCasePatternMatchingErrors.fs index 53e537e2d23..7c4eef06e9d 100644 --- a/tests/FSharp.Compiler.ComponentTests/ErrorMessages/UnionCasePatternMatchingErrors.fs +++ b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/UnionCasePatternMatchingErrors.fs @@ -245,6 +245,8 @@ let myVal = (Warning 3548, Line 17, Col 20, Line 17, Col 23, "Pattern discard is not allowed for union case that takes no data.") ] + +// FIXME: Rename and move to a more appropriate test file [] let ``Separator between member and type annotation interpreted as operator`` () = FSharp """ @@ -263,6 +265,14 @@ type IFoo<'T> = |> typecheck |> shouldSucceed +[] +let ``Separator between member and type annotation interpreted as operator 3`` () = + Fsx """ +let (>:) a b = a + b + """ + |> typecheck + |> shouldSucceed + [] let ``Multiple pattern discards not allowed for union case that takes no data with Lang 7`` () = FSharp """ From 6684f531cde2e6f169eda152860a0a57e15d19c8 Mon Sep 17 00:00:00 2001 From: Edgar Gonzalez Date: Sun, 10 Sep 2023 21:27:07 +0200 Subject: [PATCH 3/6] more tests --- src/Compiler/Checking/CheckDeclarations.fs | 42 +++++++++++++ .../UnionCasePatternMatchingErrors.fs | 60 ++++++++++++++++++- 2 files changed, 100 insertions(+), 2 deletions(-) diff --git a/src/Compiler/Checking/CheckDeclarations.fs b/src/Compiler/Checking/CheckDeclarations.fs index 8f41152c420..2ff17903c15 100644 --- a/src/Compiler/Checking/CheckDeclarations.fs +++ b/src/Compiler/Checking/CheckDeclarations.fs @@ -178,6 +178,25 @@ module MutRecShapes = let iterTyconsWithEnv f1 env xs = iterWithEnv f1 (fun _env _x -> ()) (fun _env _x -> ()) (fun _env _x -> ()) env xs +let private CheckForLetNotAllowedInOperatorNames (binds : SynBinding list) = + for bnd in binds do + let (SynBinding(headPat= headPat; range = _m)) = bnd + match headPat with + | SynPat.LongIdent(longDotId= headPatIdent; argPats = SynArgPats.Pats(pats)) -> + for ident in headPatIdent.LongIdent do + if ident.idText = "op_GreaterColon" then + deprecatedWithError (FSComp.SR.lexCharNotAllowedInOperatorNames(":")) ident.idRange + for pat in pats do + match pat with + | SynPat.Named(ident= SynIdent(ident= ident)) -> + if ident.idText = "op_GreaterColon" then + deprecatedWithError (FSComp.SR.lexCharNotAllowedInOperatorNames(":")) ident.idRange + | _ -> () + | SynPat.Named(ident= SynIdent(ident= ident)) -> + if ident.idText = "op_GreaterColon" then + deprecatedWithError (FSComp.SR.lexCharNotAllowedInOperatorNames(":")) ident.idRange + + | _ -> () /// Indicates a declaration is contained in the given module let ModuleOrNamespaceContainerInfo modref = @@ -4148,6 +4167,17 @@ module TcDeclarations = match ds with | d :: ds when isImplicitInherit d -> ds // skip inherit call if it comes next | _ -> ds + + let members = + ds + |> List.takeUntil(isMember) + |> snd + |> List.choose(fun x -> + match x with + | SynMemberDefn.Member(memberDefn, _) -> Some memberDefn + | _ -> None) + + CheckForLetNotAllowedInOperatorNames members // Skip over 'let' and 'do' bindings let _, ds = ds |> List.takeUntil (function SynMemberDefn.LetBindings _ -> false | _ -> true) @@ -4175,6 +4205,17 @@ module TcDeclarations = CheckDuplicatesArgNames synVal m | _ -> () + let members = + ds + |> List.takeUntil(isMember) + |> snd + |> List.choose(fun x -> + match x with + | SynMemberDefn.Member(memberDefn, _) -> Some memberDefn + | _ -> None) + + CheckForLetNotAllowedInOperatorNames members + // Classic class construction let _, ds = List.takeUntil (allFalse [isMember;isAbstractSlot;isInterface;isInherit;isField;isTycon]) ds match ds with @@ -5005,6 +5046,7 @@ let rec TcModuleOrNamespaceElementNonMutRec (cenv: cenv) parent typeNames scopem | Parent parentModule -> let containerInfo = ModuleOrNamespaceContainerInfo parentModule + CheckForLetNotAllowedInOperatorNames binds if letrec then let scopem = unionRanges m scopem let binds = binds |> List.map (fun bind -> RecDefnBindingInfo(containerInfo, NoNewSlots, ModuleOrMemberBinding, bind)) diff --git a/tests/FSharp.Compiler.ComponentTests/ErrorMessages/UnionCasePatternMatchingErrors.fs b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/UnionCasePatternMatchingErrors.fs index 7c4eef06e9d..a4a7cc99589 100644 --- a/tests/FSharp.Compiler.ComponentTests/ErrorMessages/UnionCasePatternMatchingErrors.fs +++ b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/UnionCasePatternMatchingErrors.fs @@ -268,10 +268,66 @@ type IFoo<'T> = [] let ``Separator between member and type annotation interpreted as operator 3`` () = Fsx """ -let (>:) a b = a + b +let (>:) (>:) e1 e2 = if e1 then e1 else false """ |> typecheck - |> shouldSucceed + |> shouldFail + |> withDiagnostics [ + (Error 35, Line 2, Col 6, Line 2, Col 8, "This construct is deprecated: ':' is not permitted as a character in operator names and is reserved for future use") + (Error 35, Line 2, Col 11, Line 2, Col 13, "This construct is deprecated: ':' is not permitted as a character in operator names and is reserved for future use") + ] + +[] +let ``Separator between member and type annotation interpreted as operator 4`` () = + Fsx """ +let (>:) e1 e2 = if e1 then e1 else false + """ + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Error 35, Line 2, Col 6, Line 2, Col 8, "This construct is deprecated: ':' is not permitted as a character in operator names and is reserved for future use") + ] + +[] +let ``Separator between member and type annotation interpreted as operator 5`` () = + Fsx """ +type Vector() = + static member (>:) (>:) = false + """ + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Error 35, Line 3, Col 20, Line 3, Col 22, "This construct is deprecated: ':' is not permitted as a character in operator names and is reserved for future use") + (Error 35, Line 3, Col 25, Line 3, Col 27, "This construct is deprecated: ':' is not permitted as a character in operator names and is reserved for future use") + (Warning 1173, Line 3, Col 20, Line 3, Col 22, "Infix operator member '>:' has 1 initial argument(s). Expected a tuple of 2 arguments, e.g. static member (+) (x,y) = ...") + ] + +[] +let ``Separator between member and type annotation interpreted as operator 7`` () = + Fsx """ +type Vector = + static member (>:) (>:) = false + """ + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Error 35, Line 3, Col 20, Line 3, Col 22, "This construct is deprecated: ':' is not permitted as a character in operator names and is reserved for future use") + (Error 35, Line 3, Col 25, Line 3, Col 27, "This construct is deprecated: ':' is not permitted as a character in operator names and is reserved for future use") + (Warning 1173, Line 3, Col 20, Line 3, Col 22, "Infix operator member '>:' has 1 initial argument(s). Expected a tuple of 2 arguments, e.g. static member (+) (x,y) = ...") + ] + +[] +let ``Separator between member and type annotation interpreted as operator 6`` () = + Fsx """ +type Vector() = + static member (>:) = false + """ + |> typecheck + |> shouldFail + |> withDiagnostics [ + (Error 35, Line 3, Col 20, Line 3, Col 22, "This construct is deprecated: ':' is not permitted as a character in operator names and is reserved for future use") + (Warning 1172, Line 3, Col 20, Line 3, Col 22, "Infix operator member '>:' has no arguments. Expected a tuple of 2 arguments, e.g. static member (+) (x,y) = ...") + ] [] let ``Multiple pattern discards not allowed for union case that takes no data with Lang 7`` () = From 0b0fe3c85096ea0422680a8415fd4633bb2f0f05 Mon Sep 17 00:00:00 2001 From: Edgar Gonzalez Date: Mon, 11 Sep 2023 11:06:43 +0200 Subject: [PATCH 4/6] move tests --- .../OperatorNames/E_OperatorGreaterColon.fs | 13 +++ .../OperatorNames/OperatorNames.fs | 18 ++++ .../ErrorMessages/ClassesTests.fs | 18 ++++ .../UnionCasePatternMatchingErrors.fs | 84 ------------------- 4 files changed, 49 insertions(+), 84 deletions(-) create mode 100644 tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/OperatorNames/E_OperatorGreaterColon.fs diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/OperatorNames/E_OperatorGreaterColon.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/OperatorNames/E_OperatorGreaterColon.fs new file mode 100644 index 00000000000..3ab6fe4037f --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/OperatorNames/E_OperatorGreaterColon.fs @@ -0,0 +1,13 @@ +module GreaterColonOperator = + let (>:) e1 e2 = if e1 then e1 else false + + let (>:) (>:) e1 e2 = if e1 then e1 else false + + type Vector() = + static member (>:) = false + + type Vector1 = + static member (>:) (>:) = false + + type Vector3() = + static member (>:) (>:) = false diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/OperatorNames/OperatorNames.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/OperatorNames/OperatorNames.fs index e9cd52bafba..a56fd0e92c9 100644 --- a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/OperatorNames/OperatorNames.fs +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/OperatorNames/OperatorNames.fs @@ -74,3 +74,21 @@ module OperatorNames = |> withOptions ["--warnaserror+"; "--nowarn:3370"; "--nowarn:988"] |> compileExeAndRun |> shouldSucceed + + [] + let``E_OperatorGreaterColon_fs`` compilation = + compilation + |> withOptions ["--nowarn:1172" ; "--nowarn:1173"] + |> asExe + |> compile + |> shouldFail + |> withDiagnostics [ + (Error 35, Line 2, Col 10, Line 2, Col 12, "This construct is deprecated: ':' is not permitted as a character in operator names and is reserved for future use") + (Error 35, Line 4, Col 10, Line 4, Col 12, "This construct is deprecated: ':' is not permitted as a character in operator names and is reserved for future use") + (Error 35, Line 4, Col 15, Line 4, Col 17, "This construct is deprecated: ':' is not permitted as a character in operator names and is reserved for future use") + (Error 35, Line 7, Col 24, Line 7, Col 26, "This construct is deprecated: ':' is not permitted as a character in operator names and is reserved for future use") + (Error 35, Line 10, Col 24, Line 10, Col 26, "This construct is deprecated: ':' is not permitted as a character in operator names and is reserved for future use") + (Error 35, Line 10, Col 29, Line 10, Col 31, "This construct is deprecated: ':' is not permitted as a character in operator names and is reserved for future use") + (Error 35, Line 13, Col 24, Line 13, Col 26, "This construct is deprecated: ':' is not permitted as a character in operator names and is reserved for future use") + (Error 35, Line 13, Col 29, Line 13, Col 31, "This construct is deprecated: ':' is not permitted as a character in operator names and is reserved for future use") + ] diff --git a/tests/FSharp.Compiler.ComponentTests/ErrorMessages/ClassesTests.fs b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/ClassesTests.fs index a43e7eb2491..41a672132be 100644 --- a/tests/FSharp.Compiler.ComponentTests/ErrorMessages/ClassesTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/ClassesTests.fs @@ -686,4 +686,22 @@ type X = app |> withLangVersion80 |> compile + |> shouldSucceed + + [] + let ``No separator between member and type annotation`` () = + FSharp """ + type IFoo<'T> = + abstract member Bar<'T>: string -> unit + """ + |> typecheck + |> shouldSucceed + + [] + let ``Separator between member and type annotation`` () = + FSharp """ + type IFoo<'T> = + abstract member Bar<'T> : string -> unit + """ + |> typecheck |> shouldSucceed \ No newline at end of file diff --git a/tests/FSharp.Compiler.ComponentTests/ErrorMessages/UnionCasePatternMatchingErrors.fs b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/UnionCasePatternMatchingErrors.fs index a4a7cc99589..df94ca89e0e 100644 --- a/tests/FSharp.Compiler.ComponentTests/ErrorMessages/UnionCasePatternMatchingErrors.fs +++ b/tests/FSharp.Compiler.ComponentTests/ErrorMessages/UnionCasePatternMatchingErrors.fs @@ -245,90 +245,6 @@ let myVal = (Warning 3548, Line 17, Col 20, Line 17, Col 23, "Pattern discard is not allowed for union case that takes no data.") ] - -// FIXME: Rename and move to a more appropriate test file -[] -let ``Separator between member and type annotation interpreted as operator`` () = - FSharp """ -type IFoo<'T> = - abstract member Bar<'T>: string -> unit - """ - |> typecheck - |> shouldSucceed - -[] -let ``Separator between member and type annotation interpreted as operator 2`` () = - FSharp """ -type IFoo<'T> = - abstract member Bar<'T> : string -> unit - """ - |> typecheck - |> shouldSucceed - -[] -let ``Separator between member and type annotation interpreted as operator 3`` () = - Fsx """ -let (>:) (>:) e1 e2 = if e1 then e1 else false - """ - |> typecheck - |> shouldFail - |> withDiagnostics [ - (Error 35, Line 2, Col 6, Line 2, Col 8, "This construct is deprecated: ':' is not permitted as a character in operator names and is reserved for future use") - (Error 35, Line 2, Col 11, Line 2, Col 13, "This construct is deprecated: ':' is not permitted as a character in operator names and is reserved for future use") - ] - -[] -let ``Separator between member and type annotation interpreted as operator 4`` () = - Fsx """ -let (>:) e1 e2 = if e1 then e1 else false - """ - |> typecheck - |> shouldFail - |> withDiagnostics [ - (Error 35, Line 2, Col 6, Line 2, Col 8, "This construct is deprecated: ':' is not permitted as a character in operator names and is reserved for future use") - ] - -[] -let ``Separator between member and type annotation interpreted as operator 5`` () = - Fsx """ -type Vector() = - static member (>:) (>:) = false - """ - |> typecheck - |> shouldFail - |> withDiagnostics [ - (Error 35, Line 3, Col 20, Line 3, Col 22, "This construct is deprecated: ':' is not permitted as a character in operator names and is reserved for future use") - (Error 35, Line 3, Col 25, Line 3, Col 27, "This construct is deprecated: ':' is not permitted as a character in operator names and is reserved for future use") - (Warning 1173, Line 3, Col 20, Line 3, Col 22, "Infix operator member '>:' has 1 initial argument(s). Expected a tuple of 2 arguments, e.g. static member (+) (x,y) = ...") - ] - -[] -let ``Separator between member and type annotation interpreted as operator 7`` () = - Fsx """ -type Vector = - static member (>:) (>:) = false - """ - |> typecheck - |> shouldFail - |> withDiagnostics [ - (Error 35, Line 3, Col 20, Line 3, Col 22, "This construct is deprecated: ':' is not permitted as a character in operator names and is reserved for future use") - (Error 35, Line 3, Col 25, Line 3, Col 27, "This construct is deprecated: ':' is not permitted as a character in operator names and is reserved for future use") - (Warning 1173, Line 3, Col 20, Line 3, Col 22, "Infix operator member '>:' has 1 initial argument(s). Expected a tuple of 2 arguments, e.g. static member (+) (x,y) = ...") - ] - -[] -let ``Separator between member and type annotation interpreted as operator 6`` () = - Fsx """ -type Vector() = - static member (>:) = false - """ - |> typecheck - |> shouldFail - |> withDiagnostics [ - (Error 35, Line 3, Col 20, Line 3, Col 22, "This construct is deprecated: ':' is not permitted as a character in operator names and is reserved for future use") - (Warning 1172, Line 3, Col 20, Line 3, Col 22, "Infix operator member '>:' has no arguments. Expected a tuple of 2 arguments, e.g. static member (+) (x,y) = ...") - ] - [] let ``Multiple pattern discards not allowed for union case that takes no data with Lang 7`` () = FSharp """ From 133a5efea3077d6246cc1468cc44ce27bd1f6b2d Mon Sep 17 00:00:00 2001 From: Edgar Gonzalez Date: Tue, 12 Sep 2023 12:23:47 +0200 Subject: [PATCH 5/6] WIP more tests --- ...aterColon.fs => E_OperatorGreaterColon01.fs} | 0 .../OperatorNames/E_OperatorGreaterColon02.fs | 17 +++++++++++++++++ .../OperatorNames/OperatorNames.fs | 15 +++++++++++++-- 3 files changed, 30 insertions(+), 2 deletions(-) rename tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/OperatorNames/{E_OperatorGreaterColon.fs => E_OperatorGreaterColon01.fs} (100%) create mode 100644 tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/OperatorNames/E_OperatorGreaterColon02.fs diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/OperatorNames/E_OperatorGreaterColon.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/OperatorNames/E_OperatorGreaterColon01.fs similarity index 100% rename from tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/OperatorNames/E_OperatorGreaterColon.fs rename to tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/OperatorNames/E_OperatorGreaterColon01.fs diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/OperatorNames/E_OperatorGreaterColon02.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/OperatorNames/E_OperatorGreaterColon02.fs new file mode 100644 index 00000000000..97fe4563a82 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/OperatorNames/E_OperatorGreaterColon02.fs @@ -0,0 +1,17 @@ +type (>:) = class end + +// type Vector(>:) = class end + +// type Vector2(>:) = interface end + +// module (>:) = +// begin +// type T = int +// let (>:) = 1 +// end + +// namespace (>:) = +// begin +// type T = int +// let (>:) = 1 +// end diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/OperatorNames/OperatorNames.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/OperatorNames/OperatorNames.fs index a56fd0e92c9..451fd76222c 100644 --- a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/OperatorNames/OperatorNames.fs +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/OperatorNames/OperatorNames.fs @@ -75,8 +75,8 @@ module OperatorNames = |> compileExeAndRun |> shouldSucceed - [] - let``E_OperatorGreaterColon_fs`` compilation = + [] + let``E_OperatorGreaterColon01_fs`` compilation = compilation |> withOptions ["--nowarn:1172" ; "--nowarn:1173"] |> asExe @@ -92,3 +92,14 @@ module OperatorNames = (Error 35, Line 13, Col 24, Line 13, Col 26, "This construct is deprecated: ':' is not permitted as a character in operator names and is reserved for future use") (Error 35, Line 13, Col 29, Line 13, Col 31, "This construct is deprecated: ':' is not permitted as a character in operator names and is reserved for future use") ] + + [] + let ``E_OperatorGreaterColon02_fs`` compilation = + compilation + |> withOptions ["--nowarn:1172" ; "--nowarn:1173"] + |> asFsx + |> runFsi + |> shouldFail + |> withDiagnostics [ + + ] \ No newline at end of file From a1d5a18e5d08796a2642d286e59df4987d23dcf9 Mon Sep 17 00:00:00 2001 From: Edgar Gonzalez Date: Thu, 12 Oct 2023 13:05:21 +0100 Subject: [PATCH 6/6] Revert check for custom operator during typechecking --- src/Compiler/Checking/CheckDeclarations.fs | 43 ------------------- .../OperatorNames/BasicOperatorNames.fs | 2 + .../OperatorNames/E_OperatorGreaterColon01.fs | 13 ------ .../OperatorNames/E_OperatorGreaterColon02.fs | 17 -------- .../OperatorNames/OperatorNames.fs | 31 +------------ 5 files changed, 3 insertions(+), 103 deletions(-) delete mode 100644 tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/OperatorNames/E_OperatorGreaterColon01.fs delete mode 100644 tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/OperatorNames/E_OperatorGreaterColon02.fs diff --git a/src/Compiler/Checking/CheckDeclarations.fs b/src/Compiler/Checking/CheckDeclarations.fs index 2ff17903c15..c473df25b9b 100644 --- a/src/Compiler/Checking/CheckDeclarations.fs +++ b/src/Compiler/Checking/CheckDeclarations.fs @@ -178,26 +178,6 @@ module MutRecShapes = let iterTyconsWithEnv f1 env xs = iterWithEnv f1 (fun _env _x -> ()) (fun _env _x -> ()) (fun _env _x -> ()) env xs -let private CheckForLetNotAllowedInOperatorNames (binds : SynBinding list) = - for bnd in binds do - let (SynBinding(headPat= headPat; range = _m)) = bnd - match headPat with - | SynPat.LongIdent(longDotId= headPatIdent; argPats = SynArgPats.Pats(pats)) -> - for ident in headPatIdent.LongIdent do - if ident.idText = "op_GreaterColon" then - deprecatedWithError (FSComp.SR.lexCharNotAllowedInOperatorNames(":")) ident.idRange - for pat in pats do - match pat with - | SynPat.Named(ident= SynIdent(ident= ident)) -> - if ident.idText = "op_GreaterColon" then - deprecatedWithError (FSComp.SR.lexCharNotAllowedInOperatorNames(":")) ident.idRange - | _ -> () - | SynPat.Named(ident= SynIdent(ident= ident)) -> - if ident.idText = "op_GreaterColon" then - deprecatedWithError (FSComp.SR.lexCharNotAllowedInOperatorNames(":")) ident.idRange - - | _ -> () - /// Indicates a declaration is contained in the given module let ModuleOrNamespaceContainerInfo modref = ContainerInfo(Parent modref, Some(MemberOrValContainerInfo(modref, None, None, NoSafeInitInfo, []))) @@ -4167,17 +4147,6 @@ module TcDeclarations = match ds with | d :: ds when isImplicitInherit d -> ds // skip inherit call if it comes next | _ -> ds - - let members = - ds - |> List.takeUntil(isMember) - |> snd - |> List.choose(fun x -> - match x with - | SynMemberDefn.Member(memberDefn, _) -> Some memberDefn - | _ -> None) - - CheckForLetNotAllowedInOperatorNames members // Skip over 'let' and 'do' bindings let _, ds = ds |> List.takeUntil (function SynMemberDefn.LetBindings _ -> false | _ -> true) @@ -4205,17 +4174,6 @@ module TcDeclarations = CheckDuplicatesArgNames synVal m | _ -> () - let members = - ds - |> List.takeUntil(isMember) - |> snd - |> List.choose(fun x -> - match x with - | SynMemberDefn.Member(memberDefn, _) -> Some memberDefn - | _ -> None) - - CheckForLetNotAllowedInOperatorNames members - // Classic class construction let _, ds = List.takeUntil (allFalse [isMember;isAbstractSlot;isInterface;isInherit;isField;isTycon]) ds match ds with @@ -5046,7 +5004,6 @@ let rec TcModuleOrNamespaceElementNonMutRec (cenv: cenv) parent typeNames scopem | Parent parentModule -> let containerInfo = ModuleOrNamespaceContainerInfo parentModule - CheckForLetNotAllowedInOperatorNames binds if letrec then let scopem = unionRanges m scopem let binds = binds |> List.map (fun bind -> RecDefnBindingInfo(containerInfo, NoNewSlots, ModuleOrMemberBinding, bind)) diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/OperatorNames/BasicOperatorNames.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/OperatorNames/BasicOperatorNames.fs index 678198d625c..fa340382024 100644 --- a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/OperatorNames/BasicOperatorNames.fs +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/OperatorNames/BasicOperatorNames.fs @@ -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 diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/OperatorNames/E_OperatorGreaterColon01.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/OperatorNames/E_OperatorGreaterColon01.fs deleted file mode 100644 index 3ab6fe4037f..00000000000 --- a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/OperatorNames/E_OperatorGreaterColon01.fs +++ /dev/null @@ -1,13 +0,0 @@ -module GreaterColonOperator = - let (>:) e1 e2 = if e1 then e1 else false - - let (>:) (>:) e1 e2 = if e1 then e1 else false - - type Vector() = - static member (>:) = false - - type Vector1 = - static member (>:) (>:) = false - - type Vector3() = - static member (>:) (>:) = false diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/OperatorNames/E_OperatorGreaterColon02.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/OperatorNames/E_OperatorGreaterColon02.fs deleted file mode 100644 index 97fe4563a82..00000000000 --- a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/OperatorNames/E_OperatorGreaterColon02.fs +++ /dev/null @@ -1,17 +0,0 @@ -type (>:) = class end - -// type Vector(>:) = class end - -// type Vector2(>:) = interface end - -// module (>:) = -// begin -// type T = int -// let (>:) = 1 -// end - -// namespace (>:) = -// begin -// type T = int -// let (>:) = 1 -// end diff --git a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/OperatorNames/OperatorNames.fs b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/OperatorNames/OperatorNames.fs index 451fd76222c..89b5d4c4ad0 100644 --- a/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/OperatorNames/OperatorNames.fs +++ b/tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/OperatorNames/OperatorNames.fs @@ -73,33 +73,4 @@ module OperatorNames = |> asExe |> withOptions ["--warnaserror+"; "--nowarn:3370"; "--nowarn:988"] |> compileExeAndRun - |> shouldSucceed - - [] - let``E_OperatorGreaterColon01_fs`` compilation = - compilation - |> withOptions ["--nowarn:1172" ; "--nowarn:1173"] - |> asExe - |> compile - |> shouldFail - |> withDiagnostics [ - (Error 35, Line 2, Col 10, Line 2, Col 12, "This construct is deprecated: ':' is not permitted as a character in operator names and is reserved for future use") - (Error 35, Line 4, Col 10, Line 4, Col 12, "This construct is deprecated: ':' is not permitted as a character in operator names and is reserved for future use") - (Error 35, Line 4, Col 15, Line 4, Col 17, "This construct is deprecated: ':' is not permitted as a character in operator names and is reserved for future use") - (Error 35, Line 7, Col 24, Line 7, Col 26, "This construct is deprecated: ':' is not permitted as a character in operator names and is reserved for future use") - (Error 35, Line 10, Col 24, Line 10, Col 26, "This construct is deprecated: ':' is not permitted as a character in operator names and is reserved for future use") - (Error 35, Line 10, Col 29, Line 10, Col 31, "This construct is deprecated: ':' is not permitted as a character in operator names and is reserved for future use") - (Error 35, Line 13, Col 24, Line 13, Col 26, "This construct is deprecated: ':' is not permitted as a character in operator names and is reserved for future use") - (Error 35, Line 13, Col 29, Line 13, Col 31, "This construct is deprecated: ':' is not permitted as a character in operator names and is reserved for future use") - ] - - [] - let ``E_OperatorGreaterColon02_fs`` compilation = - compilation - |> withOptions ["--nowarn:1172" ; "--nowarn:1173"] - |> asFsx - |> runFsi - |> shouldFail - |> withDiagnostics [ - - ] \ No newline at end of file + |> shouldSucceed \ No newline at end of file