diff --git a/include/swift/Parse/Parser.h b/include/swift/Parse/Parser.h index 1c4584e71eca9..57c18ef074c6b 100644 --- a/include/swift/Parse/Parser.h +++ b/include/swift/Parse/Parser.h @@ -1116,7 +1116,7 @@ class Parser { ParsedAccessors &accessors, AbstractStorageDecl *storage, SourceLoc StaticLoc); - ParserResult parseDeclVarGetSet(Pattern *pattern, + ParserResult parseDeclVarGetSet(PatternBindingEntry &entry, ParseDeclOptions Flags, SourceLoc StaticLoc, StaticSpellingKind StaticSpelling, diff --git a/lib/IDE/SyntaxModel.cpp b/lib/IDE/SyntaxModel.cpp index 7504a1b6bf183..353006ee22e4e 100644 --- a/lib/IDE/SyntaxModel.cpp +++ b/lib/IDE/SyntaxModel.cpp @@ -990,7 +990,9 @@ bool ModelASTWalker::walkToDeclPre(Decl *D) { if (bracesRange.isValid()) SN.BodyRange = innerCharSourceRangeFromSourceRange(SM, bracesRange); SourceLoc NRStart = VD->getNameLoc(); - SourceLoc NREnd = NRStart.getAdvancedLoc(VD->getName().getLength()); + SourceLoc NREnd = (!VD->getName().empty() + ? NRStart.getAdvancedLoc(VD->getName().getLength()) + : NRStart); SN.NameRange = CharSourceRange(SM, NRStart, NREnd); SN.TypeRange = charSourceRangeFromSourceRange(SM, VD->getTypeSourceRangeForDiagnostics()); diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp index 6c387e639640b..fa9ace4441e27 100644 --- a/lib/Parse/ParseDecl.cpp +++ b/lib/Parse/ParseDecl.cpp @@ -5680,14 +5680,16 @@ ParserStatus Parser::parseGetSet(ParseDeclOptions Flags, /// Parse the brace-enclosed getter and setter for a variable. ParserResult -Parser::parseDeclVarGetSet(Pattern *pattern, ParseDeclOptions Flags, +Parser::parseDeclVarGetSet(PatternBindingEntry &entry, ParseDeclOptions Flags, SourceLoc StaticLoc, StaticSpellingKind StaticSpelling, SourceLoc VarLoc, bool hasInitializer, const DeclAttributes &Attributes, SmallVectorImpl &Decls) { bool Invalid = false; - + + auto *pattern = entry.getPattern(); + // The grammar syntactically requires a simple identifier for the variable // name. Complain if that isn't what we got. But for recovery purposes, // make an effort to look through other things anyway. @@ -5730,22 +5732,12 @@ Parser::parseDeclVarGetSet(Pattern *pattern, ParseDeclOptions Flags, VarDecl::Introducer::Var, VarLoc, Identifier(), CurDeclContext); - storage->setImplicit(true); storage->setInvalid(); - Pattern *pattern = + pattern = TypedPattern::createImplicit(Context, new (Context) NamedPattern(storage), ErrorType::get(Context)); - PatternBindingEntry entry(pattern, /*EqualLoc*/ SourceLoc(), - /*Init*/ nullptr, /*InitContext*/ nullptr); - auto binding = PatternBindingDecl::create(Context, StaticLoc, - StaticSpelling, - VarLoc, entry, CurDeclContext); - binding->setInvalid(); - storage->setParentPatternBinding(binding); - - Decls.push_back(binding); - Decls.push_back(storage); + entry.setPattern(pattern); } // Parse getter and setter. @@ -6157,7 +6149,8 @@ Parser::parseDeclVar(ParseDeclOptions Flags, if (Tok.is(tok::l_brace)) { HasAccessors = true; auto boundVar = - parseDeclVarGetSet(pattern, Flags, StaticLoc, StaticSpelling, VarLoc, + parseDeclVarGetSet(PBDEntries.back(), + Flags, StaticLoc, StaticSpelling, VarLoc, PatternInit != nullptr, Attributes, Decls); if (boundVar.hasCodeCompletion()) return makeResult(makeParserCodeCompletionStatus()); diff --git a/test/Index/invalid_code.swift b/test/Index/invalid_code.swift index 8cac081c70535..9f29ce906eff1 100644 --- a/test/Index/invalid_code.swift +++ b/test/Index/invalid_code.swift @@ -1,6 +1,5 @@ // RUN: %target-swift-ide-test -print-indexed-symbols -include-locals -source-filename %s | %FileCheck %s -// CHECK: [[@LINE+1]]:8 | struct/Swift | Int | {{.*}} | Ref | rel: 0 var _: Int { get { return 1 } } func test() { diff --git a/test/Parse/pattern_without_variables.swift b/test/Parse/pattern_without_variables.swift index d9317ce325dba..7ecad6f832f1a 100644 --- a/test/Parse/pattern_without_variables.swift +++ b/test/Parse/pattern_without_variables.swift @@ -40,5 +40,4 @@ func testVarLetPattern(a : SimpleEnum) { class SR10903 { static var _: Int { 0 } //expected-error {{getter/setter can only be defined for a single variable}} - //expected-error@-1 {{property declaration does not bind any variables}} } diff --git a/test/SourceKit/DocumentStructure/structure.swift.foobar.response b/test/SourceKit/DocumentStructure/structure.swift.foobar.response index e5b4e3c2c128c..56f7646264ae6 100644 --- a/test/SourceKit/DocumentStructure/structure.swift.foobar.response +++ b/test/SourceKit/DocumentStructure/structure.swift.foobar.response @@ -573,11 +573,10 @@ key.kind: source.lang.swift.decl.var.global, key.accessibility: source.lang.swift.accessibility.internal, key.setter_accessibility: source.lang.swift.accessibility.internal, - key.name: "Qtys", key.offset: 1079, - key.length: 15, - key.nameoffset: 1089, - key.namelength: 4 + key.length: 3, + key.nameoffset: 1079, + key.namelength: 0 }, { key.kind: source.lang.swift.stmt.foreach, diff --git a/test/SourceKit/DocumentStructure/structure.swift.response b/test/SourceKit/DocumentStructure/structure.swift.response index ac24e47f8f08d..411d00f2fdb88 100644 --- a/test/SourceKit/DocumentStructure/structure.swift.response +++ b/test/SourceKit/DocumentStructure/structure.swift.response @@ -573,11 +573,10 @@ key.kind: source.lang.swift.decl.var.global, key.accessibility: source.lang.swift.accessibility.internal, key.setter_accessibility: source.lang.swift.accessibility.internal, - key.name: "Qtys", key.offset: 1079, - key.length: 15, - key.nameoffset: 1089, - key.namelength: 4 + key.length: 3, + key.nameoffset: 1079, + key.namelength: 0 }, { key.kind: source.lang.swift.stmt.foreach,