From fb767e981a31f940fef1ab9153652e178b9552c6 Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Thu, 30 Nov 2023 12:30:44 +0100 Subject: [PATCH] Bugfix - 'static meme x = x' should fail (#16345) * Make 'static meme' fail as it should * New attempt * Change error message * Update tests/service/SyntaxTreeTests.fs Co-authored-by: Adam Boniecki <20281641+abonie@users.noreply.github.com> --------- Co-authored-by: Adam Boniecki <20281641+abonie@users.noreply.github.com> --- src/Compiler/FSComp.txt | 3 +- src/Compiler/pars.fsy | 3 + src/Compiler/xlf/FSComp.txt.cs.xlf | 5 ++ src/Compiler/xlf/FSComp.txt.de.xlf | 5 ++ src/Compiler/xlf/FSComp.txt.es.xlf | 5 ++ src/Compiler/xlf/FSComp.txt.fr.xlf | 5 ++ src/Compiler/xlf/FSComp.txt.it.xlf | 5 ++ src/Compiler/xlf/FSComp.txt.ja.xlf | 5 ++ src/Compiler/xlf/FSComp.txt.ko.xlf | 5 ++ src/Compiler/xlf/FSComp.txt.pl.xlf | 5 ++ src/Compiler/xlf/FSComp.txt.pt-BR.xlf | 5 ++ src/Compiler/xlf/FSComp.txt.ru.xlf | 5 ++ src/Compiler/xlf/FSComp.txt.tr.xlf | 5 ++ src/Compiler/xlf/FSComp.txt.zh-Hans.xlf | 5 ++ src/Compiler/xlf/FSComp.txt.zh-Hant.xlf | 5 ++ tests/service/SyntaxTreeTests.fs | 2 +- .../Member/MemberMispelledToMeme.fs | 2 + .../Member/MemberMispelledToMeme.fs.bsl | 62 +++++++++++++++++++ 18 files changed, 135 insertions(+), 2 deletions(-) create mode 100644 tests/service/data/SyntaxTree/Member/MemberMispelledToMeme.fs create mode 100644 tests/service/data/SyntaxTree/Member/MemberMispelledToMeme.fs.bsl diff --git a/src/Compiler/FSComp.txt b/src/Compiler/FSComp.txt index d7e08c6e30b..e2aaa935a92 100644 --- a/src/Compiler/FSComp.txt +++ b/src/Compiler/FSComp.txt @@ -1735,4 +1735,5 @@ featureReuseSameFieldsInStructUnions,"Share underlying fields in a [] di 3855,tcNoStaticMemberFoundForOverride,"No static abstract member was found that corresponds to this override" 3859,tcNoStaticPropertyFoundForOverride,"No static abstract property was found that corresponds to this override" 3860,chkStaticMembersOnObjectExpressions,"Object expressions cannot implement interfaces with static abstract members or declare static members." -3861,chkTailCallAttrOnNonRec,"The TailCall attribute should only be applied to recursive functions." \ No newline at end of file +3861,chkTailCallAttrOnNonRec,"The TailCall attribute should only be applied to recursive functions." +3862,parsStaticMemberImcompleteSyntax,"Incomplete declaration of a static construct. Use 'static let','static do','static member' or 'static val' for declaration." \ No newline at end of file diff --git a/src/Compiler/pars.fsy b/src/Compiler/pars.fsy index 2532bd8558d..a4a77de3bf5 100644 --- a/src/Compiler/pars.fsy +++ b/src/Compiler/pars.fsy @@ -1988,6 +1988,9 @@ classDefnMember: if Option.isSome $2 then errorR (Error (FSComp.SR.parsVisibilityDeclarationsShouldComePriorToIdentifier (), rhs parseState 2)) let flags = $3 + match flags with + | _, SynLeadingKeyword.Static(mStatic) -> errorR (Error (FSComp.SR.parsStaticMemberImcompleteSyntax (), mStatic)) + | _ -> () $4 $2 flags $1 rangeStart } | opt_attributes opt_access memberFlags recover diff --git a/src/Compiler/xlf/FSComp.txt.cs.xlf b/src/Compiler/xlf/FSComp.txt.cs.xlf index 67dc8a33de9..a55e3597c88 100644 --- a/src/Compiler/xlf/FSComp.txt.cs.xlf +++ b/src/Compiler/xlf/FSComp.txt.cs.xlf @@ -947,6 +947,11 @@ Tento přístup člena je nejednoznačný. Při vytváření objektu použijte závorky, např. (new SomeType(args)).MemberName' + + Incomplete declaration of a static construct. Use 'static let','static do','static member' or 'static val' for declaration. + Incomplete declaration of a static construct. Use 'static let','static do','static member' or 'static val' for declaration. + + Unexpected end of input in 'else if' or 'elif' branch of conditional expression. Expected 'elif <expr> then <expr>' or 'else if <expr> then <expr>'. Neočekávaný konec vstupu ve větvi else if nebo elif podmíněného výrazu Očekávalo se elif <expr> then <expr> nebo else if <expr> then <expr>. diff --git a/src/Compiler/xlf/FSComp.txt.de.xlf b/src/Compiler/xlf/FSComp.txt.de.xlf index 1ccf02ec1ee..61ba65dcc1e 100644 --- a/src/Compiler/xlf/FSComp.txt.de.xlf +++ b/src/Compiler/xlf/FSComp.txt.de.xlf @@ -947,6 +947,11 @@ Dieser Memberzugriff ist mehrdeutig. Setzen Sie Klammern um die Objekterstellung, z. B. "(new SomeType(args)). MemberName“ + + Incomplete declaration of a static construct. Use 'static let','static do','static member' or 'static val' for declaration. + Incomplete declaration of a static construct. Use 'static let','static do','static member' or 'static val' for declaration. + + Unexpected end of input in 'else if' or 'elif' branch of conditional expression. Expected 'elif <expr> then <expr>' or 'else if <expr> then <expr>'. Unerwartetes Ende der Eingabe im "else if"- oder "elif"-Branch des bedingten Ausdrucks. Erwartet wird: "elif <expr> then <expr>" oder "else if <expr> then <expr>". diff --git a/src/Compiler/xlf/FSComp.txt.es.xlf b/src/Compiler/xlf/FSComp.txt.es.xlf index 1efa1037c2c..3b2dd6ee6a7 100644 --- a/src/Compiler/xlf/FSComp.txt.es.xlf +++ b/src/Compiler/xlf/FSComp.txt.es.xlf @@ -947,6 +947,11 @@ Este acceso de miembro es ambiguo. Use paréntesis alrededor de la creación del objeto, por ejemplo, '(nuevo AlgúnTipo(args)).NombreMiembro' + + Incomplete declaration of a static construct. Use 'static let','static do','static member' or 'static val' for declaration. + Incomplete declaration of a static construct. Use 'static let','static do','static member' or 'static val' for declaration. + + Unexpected end of input in 'else if' or 'elif' branch of conditional expression. Expected 'elif <expr> then <expr>' or 'else if <expr> then <expr>'. Fin de entrada inesperado en la rama "else if" o "elif" de una expresión condicional. Se espera "elif <expr> then <expr>" o "else if <expr> then <expr>". diff --git a/src/Compiler/xlf/FSComp.txt.fr.xlf b/src/Compiler/xlf/FSComp.txt.fr.xlf index 1e3087c77e8..7857228abf6 100644 --- a/src/Compiler/xlf/FSComp.txt.fr.xlf +++ b/src/Compiler/xlf/FSComp.txt.fr.xlf @@ -947,6 +947,11 @@ L’accès à ce membre est ambigu. Utilisez des parenthèses autour de la création de l’objet, par exemple' (New SomeType (args)). MemberName + + Incomplete declaration of a static construct. Use 'static let','static do','static member' or 'static val' for declaration. + Incomplete declaration of a static construct. Use 'static let','static do','static member' or 'static val' for declaration. + + Unexpected end of input in 'else if' or 'elif' branch of conditional expression. Expected 'elif <expr> then <expr>' or 'else if <expr> then <expr>'. Fin d'entrée inattendue dans la branche 'else if' ou 'elif' de l'expression conditionnelle. Attendu 'elif <expr> then <expr>' ou 'else if <expr> then <expr>'. diff --git a/src/Compiler/xlf/FSComp.txt.it.xlf b/src/Compiler/xlf/FSComp.txt.it.xlf index 57e483a458c..134e094dffd 100644 --- a/src/Compiler/xlf/FSComp.txt.it.xlf +++ b/src/Compiler/xlf/FSComp.txt.it.xlf @@ -947,6 +947,11 @@ L'accesso ai membri è ambiguo. Utilizzare le parentesi intorno alla creazione oggetto, ad esempio “(New SomeType (args)). MemberName” + + Incomplete declaration of a static construct. Use 'static let','static do','static member' or 'static val' for declaration. + Incomplete declaration of a static construct. Use 'static let','static do','static member' or 'static val' for declaration. + + Unexpected end of input in 'else if' or 'elif' branch of conditional expression. Expected 'elif <expr> then <expr>' or 'else if <expr> then <expr>'. Fine dell'input imprevista nel ramo 'else if' o 'elif' dell'espressione condizionale. È previsto 'elif <expr> then <expr>' o 'else if <expr> then <expr>'. diff --git a/src/Compiler/xlf/FSComp.txt.ja.xlf b/src/Compiler/xlf/FSComp.txt.ja.xlf index 9b46ccfafcd..f5a0d7e0573 100644 --- a/src/Compiler/xlf/FSComp.txt.ja.xlf +++ b/src/Compiler/xlf/FSComp.txt.ja.xlf @@ -947,6 +947,11 @@ このメンバーへのアクセスはあいまいです。オブジェクト作成の前後にはかっこを使用してください。例: '(new SomeType(args)).MemberName' + + Incomplete declaration of a static construct. Use 'static let','static do','static member' or 'static val' for declaration. + Incomplete declaration of a static construct. Use 'static let','static do','static member' or 'static val' for declaration. + + Unexpected end of input in 'else if' or 'elif' branch of conditional expression. Expected 'elif <expr> then <expr>' or 'else if <expr> then <expr>'. 条件式の 'else if' または 'elif' 分岐の入力が予期しない形式で終了しています。'elif <expr> then <expr>' または 'else if <expr> then <expr>' が必要でした。 diff --git a/src/Compiler/xlf/FSComp.txt.ko.xlf b/src/Compiler/xlf/FSComp.txt.ko.xlf index f7cc2fe380c..7d68a8d3b73 100644 --- a/src/Compiler/xlf/FSComp.txt.ko.xlf +++ b/src/Compiler/xlf/FSComp.txt.ko.xlf @@ -947,6 +947,11 @@ 이 구성원 액세스가 모호합니다. 개체 생성 주위에 괄호를 사용하세요. 예: '(새로운 SomeType(인수)).MemberName' + + Incomplete declaration of a static construct. Use 'static let','static do','static member' or 'static val' for declaration. + Incomplete declaration of a static construct. Use 'static let','static do','static member' or 'static val' for declaration. + + Unexpected end of input in 'else if' or 'elif' branch of conditional expression. Expected 'elif <expr> then <expr>' or 'else if <expr> then <expr>'. 조건식의 'else if' 또는 'elif' 분기에서 입력이 예기치 않게 끝났습니다. 'elif <expr> then <expr>' 또는 'else if <expr> then <expr>'이 필요합니다. diff --git a/src/Compiler/xlf/FSComp.txt.pl.xlf b/src/Compiler/xlf/FSComp.txt.pl.xlf index 3980968d91c..4a768bb43a3 100644 --- a/src/Compiler/xlf/FSComp.txt.pl.xlf +++ b/src/Compiler/xlf/FSComp.txt.pl.xlf @@ -947,6 +947,11 @@ Dostęp tego elementu członkowskiego jest niejednoznaczny. W celu utworzenia obiektu użyj nawiasów, na przykład „(nowy SomeType(args)).MemberName” + + Incomplete declaration of a static construct. Use 'static let','static do','static member' or 'static val' for declaration. + Incomplete declaration of a static construct. Use 'static let','static do','static member' or 'static val' for declaration. + + Unexpected end of input in 'else if' or 'elif' branch of conditional expression. Expected 'elif <expr> then <expr>' or 'else if <expr> then <expr>'. Nieoczekiwane zakończenie danych wejściowych w gałęzi „else” wyrażenia warunkowego. Oczekiwano konstrukcji „elif <expr> then <expr>” lub „else if <expr> then <expr>”. diff --git a/src/Compiler/xlf/FSComp.txt.pt-BR.xlf b/src/Compiler/xlf/FSComp.txt.pt-BR.xlf index 130775c7141..b44ad46613e 100644 --- a/src/Compiler/xlf/FSComp.txt.pt-BR.xlf +++ b/src/Compiler/xlf/FSComp.txt.pt-BR.xlf @@ -947,6 +947,11 @@ Este acesso de membro é ambíguo. Use parênteses em torno da criação do objeto, por exemplo, '(new SomeType(args)).MemberName''. + + Incomplete declaration of a static construct. Use 'static let','static do','static member' or 'static val' for declaration. + Incomplete declaration of a static construct. Use 'static let','static do','static member' or 'static val' for declaration. + + Unexpected end of input in 'else if' or 'elif' branch of conditional expression. Expected 'elif <expr> then <expr>' or 'else if <expr> then <expr>'. Fim inesperado de entrada no branch 'else if' ou 'elif' da expressão condicional. Esperado 'elif <expr> em seguida, <expr>' ou 'else if <expr> then <expr>'. diff --git a/src/Compiler/xlf/FSComp.txt.ru.xlf b/src/Compiler/xlf/FSComp.txt.ru.xlf index fb6430843c0..55a7fa70adf 100644 --- a/src/Compiler/xlf/FSComp.txt.ru.xlf +++ b/src/Compiler/xlf/FSComp.txt.ru.xlf @@ -947,6 +947,11 @@ Неоднозначный доступ к этому элементу. Заключите операцию создания объекта в круглые скобки, например (new Объект(аргументы)).Элемент + + Incomplete declaration of a static construct. Use 'static let','static do','static member' or 'static val' for declaration. + Incomplete declaration of a static construct. Use 'static let','static do','static member' or 'static val' for declaration. + + Unexpected end of input in 'else if' or 'elif' branch of conditional expression. Expected 'elif <expr> then <expr>' or 'else if <expr> then <expr>'. Неожиданное завершение входных данных ветви "else if" или "elif" условного выражения. Ожидается "elif <expr> then <expr> " или "else if <expr> then <expr>" diff --git a/src/Compiler/xlf/FSComp.txt.tr.xlf b/src/Compiler/xlf/FSComp.txt.tr.xlf index 637a9005ed4..b1f1ba766fa 100644 --- a/src/Compiler/xlf/FSComp.txt.tr.xlf +++ b/src/Compiler/xlf/FSComp.txt.tr.xlf @@ -947,6 +947,11 @@ Bu üye erişimi belirsiz. Lütfen nesne oluşturma etrafında parantez kullanın, örneğin '(yeni SomeType (args)).MemberName’ + + Incomplete declaration of a static construct. Use 'static let','static do','static member' or 'static val' for declaration. + Incomplete declaration of a static construct. Use 'static let','static do','static member' or 'static val' for declaration. + + Unexpected end of input in 'else if' or 'elif' branch of conditional expression. Expected 'elif <expr> then <expr>' or 'else if <expr> then <expr>'. Koşullu ifadenin 'else if' veya 'elif' dalında beklenmeyen giriş sonu. 'elif <expr> then <expr>' veya 'else if <expr> then <expr>' bekleniyordu. diff --git a/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf b/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf index f4214111d30..7b87a733430 100644 --- a/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf +++ b/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf @@ -947,6 +947,11 @@ 此成员访问权限不明确。请在对象创建周围使用括号,例如 “(new SomeType(args)).MemberName” + + Incomplete declaration of a static construct. Use 'static let','static do','static member' or 'static val' for declaration. + Incomplete declaration of a static construct. Use 'static let','static do','static member' or 'static val' for declaration. + + Unexpected end of input in 'else if' or 'elif' branch of conditional expression. Expected 'elif <expr> then <expr>' or 'else if <expr> then <expr>'. 条件表达式的 "else if" 或 "elif" 分支中的输入意外结束。应为 "elif <expr> then <expr>" 或 "else if <expr> then <expr>"。 diff --git a/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf b/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf index e104b27d5d4..cc69cca8708 100644 --- a/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf +++ b/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf @@ -947,6 +947,11 @@ 此成員存取不明確。請在物件建立前後加上括弧,例如「(new SomeType(args)).MemberName」 + + Incomplete declaration of a static construct. Use 'static let','static do','static member' or 'static val' for declaration. + Incomplete declaration of a static construct. Use 'static let','static do','static member' or 'static val' for declaration. + + Unexpected end of input in 'else if' or 'elif' branch of conditional expression. Expected 'elif <expr> then <expr>' or 'else if <expr> then <expr>'. 條件運算式的 'else if' 或 'elif' 分支中出現未預期的輸入結尾。 預期為 'elif <expr> then <expr>' 或 'else if <expr> then <expr>'. diff --git a/tests/service/SyntaxTreeTests.fs b/tests/service/SyntaxTreeTests.fs index b72b20d77d9..a386e25e9e8 100644 --- a/tests/service/SyntaxTreeTests.fs +++ b/tests/service/SyntaxTreeTests.fs @@ -190,7 +190,7 @@ let ParseFile fileName = let equals = expected = actual let testUpdateBSLEnv = System.Environment.GetEnvironmentVariable("TEST_UPDATE_BSL") - if not (isNull testUpdateBSLEnv) && testUpdateBSLEnv.Trim() = "1" then + if not (isNull testUpdateBSLEnv) && testUpdateBSLEnv.Trim() = "1" && not equals then File.WriteAllText(bslPath, actual) elif not equals then File.WriteAllText(actualPath, actual) diff --git a/tests/service/data/SyntaxTree/Member/MemberMispelledToMeme.fs b/tests/service/data/SyntaxTree/Member/MemberMispelledToMeme.fs new file mode 100644 index 00000000000..3343108a07b --- /dev/null +++ b/tests/service/data/SyntaxTree/Member/MemberMispelledToMeme.fs @@ -0,0 +1,2 @@ +type Seq = + static meme average (x: int seq) = x \ No newline at end of file diff --git a/tests/service/data/SyntaxTree/Member/MemberMispelledToMeme.fs.bsl b/tests/service/data/SyntaxTree/Member/MemberMispelledToMeme.fs.bsl new file mode 100644 index 00000000000..13e0c26b915 --- /dev/null +++ b/tests/service/data/SyntaxTree/Member/MemberMispelledToMeme.fs.bsl @@ -0,0 +1,62 @@ +ImplFile + (ParsedImplFileInput + ("/root/Member/MemberMispelledToMeme.fs", false, + QualifiedNameOfFile MemberMispelledToMeme, [], [], + [SynModuleOrNamespace + ([MemberMispelledToMeme], false, AnonModule, + [Types + ([SynTypeDefn + (SynComponentInfo + ([], None, [], [Seq], + PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (1,5--1,8)), + ObjectModel + (Unspecified, + [Member + (SynBinding + (None, Normal, false, false, [], + PreXmlDoc ((2,3), FSharp.Compiler.Xml.XmlDocCollector), + SynValData + (Some { IsInstance = false + IsDispatchSlot = false + IsOverrideOrExplicitImpl = false + IsFinal = false + GetterOrSetterIsCompilerGenerated = false + MemberKind = Member }, + SynValInfo + ([[SynArgInfo ([], false, Some average)]; + [SynArgInfo ([], false, Some x)]], + SynArgInfo ([], false, None)), None), + LongIdent + (SynLongIdent ([meme], [], [None]), None, None, + Pats + [Named + (SynIdent (average, None), false, None, + (2,15--2,22)); + Paren + (Typed + (Named + (SynIdent (x, None), false, None, + (2,24--2,25)), + App + (LongIdent + (SynLongIdent ([seq], [], [None])), + None, + [LongIdent + (SynLongIdent ([int], [], [None]))], + [], None, true, (2,27--2,34)), + (2,24--2,34)), (2,23--2,35))], None, + (2,10--2,35)), None, Ident x, (2,10--2,35), + NoneAtInvisible, + { LeadingKeyword = Static (2,3--2,9) + InlineKeyword = None + EqualsRange = Some (2,36--2,37) }), (2,3--2,39))], + (2,3--2,39)), [], None, (1,5--2,39), + { LeadingKeyword = Type (1,0--1,4) + EqualsRange = Some (1,9--1,10) + WithKeyword = None })], (1,0--2,39))], PreXmlDocEmpty, [], + None, (1,0--2,39), { LeadingKeyword = None })], (true, true), + { ConditionalDirectives = [] + CodeComments = [] }, set [])) + +(2,3)-(2,9) parse error Incomplete declaration of a static construct. Use 'static let','static do','static member' or 'static val' for declaration.