From 09143a5586ec8f968dcca1fe5041f378dac527e0 Mon Sep 17 00:00:00 2001 From: kerams Date: Tue, 18 Jul 2023 12:43:12 +0200 Subject: [PATCH] Fix recovery of `member _` (#15540) * Fix recovery of member with wildcard this * Update CheckExpressions.fs * Refactor --- src/Compiler/Checking/CheckDeclarations.fs | 1 + src/Compiler/Checking/CheckExpressions.fs | 2 +- .../data/SyntaxTree/Member/Member 10.fs | 6 +++ .../data/SyntaxTree/Member/Member 10.fs.bsl | 48 +++++++++++++++++++ .../data/SyntaxTree/Member/Member 11.fs | 6 +++ .../data/SyntaxTree/Member/Member 11.fs.bsl | 48 +++++++++++++++++++ 6 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 tests/service/data/SyntaxTree/Member/Member 10.fs create mode 100644 tests/service/data/SyntaxTree/Member/Member 10.fs.bsl create mode 100644 tests/service/data/SyntaxTree/Member/Member 11.fs create mode 100644 tests/service/data/SyntaxTree/Member/Member 11.fs.bsl diff --git a/src/Compiler/Checking/CheckDeclarations.fs b/src/Compiler/Checking/CheckDeclarations.fs index 47606b18751..58bd39d1cdc 100644 --- a/src/Compiler/Checking/CheckDeclarations.fs +++ b/src/Compiler/Checking/CheckDeclarations.fs @@ -915,6 +915,7 @@ module MutRecBindingChecking = let innerState = (incrClassCtorLhsOpt, envForTycon, tpenv, recBindIdx, uncheckedBindsRev) [Phase2AIncrClassBindings (tcref, letBinds, isStatic, isRec, m)], innerState + | SynMemberDefn.Member(SynBinding(headPat = SynPat.Wild _; expr = SynExpr.ArbitraryAfterError _), _), _ | SynMemberDefn.Member(SynBinding(headPat = SynPat.FromParseError(SynPat.Wild _, _)), _), _ -> [], innerState diff --git a/src/Compiler/Checking/CheckExpressions.fs b/src/Compiler/Checking/CheckExpressions.fs index 92c93b5a623..32f9a4de039 100644 --- a/src/Compiler/Checking/CheckExpressions.fs +++ b/src/Compiler/Checking/CheckExpressions.fs @@ -3930,7 +3930,7 @@ let GetInstanceMemberThisVariable (vspec: Val, expr) = // Skip over LAM tps. Choose 'a. if vspec.IsInstanceMember then let rec firstArg e = - match stripDebugPoints e with + match stripDebugPoints e with | Expr.TyLambda (_, _, b, _, _) -> firstArg b | Expr.TyChoose (_, b, _) -> firstArg b | Expr.Lambda (_, _, _, [v], _, _, _) -> Some v diff --git a/tests/service/data/SyntaxTree/Member/Member 10.fs b/tests/service/data/SyntaxTree/Member/Member 10.fs new file mode 100644 index 00000000000..f9ed788c6e4 --- /dev/null +++ b/tests/service/data/SyntaxTree/Member/Member 10.fs @@ -0,0 +1,6 @@ +module Module + +type U = + | A + + member _ diff --git a/tests/service/data/SyntaxTree/Member/Member 10.fs.bsl b/tests/service/data/SyntaxTree/Member/Member 10.fs.bsl new file mode 100644 index 00000000000..5749df6a18b --- /dev/null +++ b/tests/service/data/SyntaxTree/Member/Member 10.fs.bsl @@ -0,0 +1,48 @@ +ImplFile + (ParsedImplFileInput + ("/root/Member/Member 10.fs", false, QualifiedNameOfFile Module, [], [], + [SynModuleOrNamespace + ([Module], false, NamedModule, + [Types + ([SynTypeDefn + (SynComponentInfo + ([], None, [], [U], + PreXmlDoc ((3,0), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (3,5--3,6)), + Simple + (Union + (None, + [SynUnionCase + ([], SynIdent (A, None), Fields [], + PreXmlDoc ((4,4), FSharp.Compiler.Xml.XmlDocCollector), + None, (4,6--4,7), { BarRange = Some (4,4--4,5) })], + (4,4--4,7)), (4,4--4,7)), + [Member + (SynBinding + (None, Normal, false, false, [], + PreXmlDoc ((6,4), FSharp.Compiler.Xml.XmlDocCollector), + SynValData + (Some { IsInstance = true + IsDispatchSlot = false + IsOverrideOrExplicitImpl = false + IsFinal = false + GetterOrSetterIsCompilerGenerated = false + MemberKind = Member }, + SynValInfo + ([[SynArgInfo ([], false, None)]; []], + SynArgInfo ([], false, None)), None), + Wild (6,11--6,12), None, + ArbitraryAfterError ("memberCore2", (6,12--6,12)), + (6,11--6,12), NoneAtInvisible, + { LeadingKeyword = Member (6,4--6,10) + InlineKeyword = None + EqualsRange = None }), (6,4--6,12))], None, + (3,5--6,12), { LeadingKeyword = Type (3,0--3,4) + EqualsRange = Some (3,7--3,8) + WithKeyword = None })], (3,0--6,12))], + PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, + (1,0--6,12), { LeadingKeyword = Module (1,0--1,6) })], (true, true), + { ConditionalDirectives = [] + CodeComments = [] }, set [])) + +(7,0)-(7,0) parse error Incomplete structured construct at or before this point in member definition. Expected 'with', '=' or other token. diff --git a/tests/service/data/SyntaxTree/Member/Member 11.fs b/tests/service/data/SyntaxTree/Member/Member 11.fs new file mode 100644 index 00000000000..390f2e0d57d --- /dev/null +++ b/tests/service/data/SyntaxTree/Member/Member 11.fs @@ -0,0 +1,6 @@ +module Module + +type U = + | A + + member _. diff --git a/tests/service/data/SyntaxTree/Member/Member 11.fs.bsl b/tests/service/data/SyntaxTree/Member/Member 11.fs.bsl new file mode 100644 index 00000000000..a4d4b985c40 --- /dev/null +++ b/tests/service/data/SyntaxTree/Member/Member 11.fs.bsl @@ -0,0 +1,48 @@ +ImplFile + (ParsedImplFileInput + ("/root/Member/Member 11.fs", false, QualifiedNameOfFile Module, [], [], + [SynModuleOrNamespace + ([Module], false, NamedModule, + [Types + ([SynTypeDefn + (SynComponentInfo + ([], None, [], [U], + PreXmlDoc ((3,0), FSharp.Compiler.Xml.XmlDocCollector), + false, None, (3,5--3,6)), + Simple + (Union + (None, + [SynUnionCase + ([], SynIdent (A, None), Fields [], + PreXmlDoc ((4,4), FSharp.Compiler.Xml.XmlDocCollector), + None, (4,6--4,7), { BarRange = Some (4,4--4,5) })], + (4,4--4,7)), (4,4--4,7)), + [Member + (SynBinding + (None, Normal, false, false, [], + PreXmlDoc ((6,4), FSharp.Compiler.Xml.XmlDocCollector), + SynValData + (Some { IsInstance = true + IsDispatchSlot = false + IsOverrideOrExplicitImpl = false + IsFinal = false + GetterOrSetterIsCompilerGenerated = false + MemberKind = Member }, + SynValInfo + ([[SynArgInfo ([], false, None)]; []], + SynArgInfo ([], false, None)), None), + FromParseError (Wild (6,10--6,10), (6,10--6,10)), None, + ArbitraryAfterError ("classDefnMember1", (6,10--6,10)), + (6,4--6,10), NoneAtInvisible, + { LeadingKeyword = Member (6,4--6,10) + InlineKeyword = None + EqualsRange = None }), (6,4--6,10))], None, + (3,5--6,10), { LeadingKeyword = Type (3,0--3,4) + EqualsRange = Some (3,7--3,8) + WithKeyword = None })], (3,0--6,10))], + PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), [], None, + (1,0--6,10), { LeadingKeyword = Module (1,0--1,6) })], (true, true), + { ConditionalDirectives = [] + CodeComments = [] }, set [])) + +(7,0)-(7,0) parse error Incomplete structured construct at or before this point in member definition. Expected identifier, '(', '(*)' or other token.