Skip to content

Commit ae7e67c

Browse files
author
David Ungar
committed
Ignore invalid PBDs
1 parent 3a3145c commit ae7e67c

File tree

1 file changed

+8
-37
lines changed

1 file changed

+8
-37
lines changed

lib/AST/ASTScopeCreation.cpp

Lines changed: 8 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -95,43 +95,14 @@ class ScopeCreator final {
9595
// Implicit nodes don't have source information for name lookup.
9696
if (d->isImplicit())
9797
return false;
98-
// Have also seen the following in an AST:
99-
// Source::
100-
//
101-
// func testInvalidKeyPathComponents() {
102-
// let _ = \.{return 0} // expected-error* {{}}
103-
// }
104-
// class X {
105-
// class var a: Int { return 1 }
106-
// }
107-
//
108-
// AST:
109-
// clang-format off
110-
// (source_file "test.swift"
111-
// (func_decl range=[test.swift:1:3 - line:3:3] "testInvalidKeyPathComponents()" interface type='() -> ()' access=internal
112-
// (parameter_list range=[test.swift:1:36 - line:1:37])
113-
// (brace_stmt range=[test.swift:1:39 - line:3:3]
114-
// (pattern_binding_decl range=[test.swift:2:5 - line:2:11]
115-
// (pattern_any)
116-
// (error_expr implicit type='<null>'))
117-
//
118-
// (pattern_binding_decl range=[test.swift:2:5 - line:2:5] <=== SOURCE RANGE WILL CONFUSE SCOPE CODE
119-
// (pattern_typed implicit type='<<error type>>'
120-
// (pattern_named '_')))
121-
// ...
122-
// clang-format on
123-
//
124-
// So test the SourceRange
125-
//
126-
// But wait!
127-
// var z = $x0 + $x1
128-
// z
129-
//
130-
// z has start == end, but must be pushed to expand source range
131-
//
132-
// So, only check source ranges for PatternBindingDecls
133-
if (isa<PatternBindingDecl>(d) && (d->getStartLoc() == d->getEndLoc()))
134-
return false;
98+
/// In \c Parser::parseDeclVarGetSet fake PBDs are created. Ignore them.
99+
/// Example:
100+
/// \code
101+
/// class SR10903 { static var _: Int { 0 } }
102+
/// \endcode
103+
if (const auto *PBD = dyn_cast<PatternBindingDecl>(d))
104+
if (PBD->isInvalid())
105+
return false;
135106
/// In
136107
/// \code
137108
/// @propertyWrapper

0 commit comments

Comments
 (0)