Skip to content

Commit 0267384

Browse files
committed
Fixup SourceKit and Tests
Patch up all the places that are making a syntactic judgement about the isInvalid() bit in a ValueDecl. They may continue to use that query, but most guard themselves on whether the interface type has been set.
1 parent efe877e commit 0267384

26 files changed

+38
-79
lines changed

lib/AST/AccessRequests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ AccessLevelRequest::evaluate(Evaluator &evaluator, ValueDecl *D) const {
8181
// Special case for dtors and enum elements: inherit from container
8282
if (D->getKind() == DeclKind::Destructor ||
8383
D->getKind() == DeclKind::EnumElement) {
84-
if (D->isInvalid()) {
84+
if (D->hasInterfaceType() && D->isInvalid()) {
8585
return AccessLevel::Private;
8686
} else {
8787
auto container = cast<NominalTypeDecl>(D->getDeclContext());

lib/AST/NameLookup.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ void DebuggerClient::anchor() {}
6969
void AccessFilteringDeclConsumer::foundDecl(
7070
ValueDecl *D, DeclVisibilityKind reason,
7171
DynamicLookupInfo dynamicLookupInfo) {
72-
if (D->isInvalid())
72+
if (D->hasInterfaceType() && D->isInvalid())
7373
return;
7474
if (!D->isAccessibleFrom(DC))
7575
return;

lib/IDE/ExprContextAnalysis.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,11 @@ Expr *swift::ide::findParsedExpr(const DeclContext *DC,
160160

161161
Type swift::ide::getReturnTypeFromContext(const DeclContext *DC) {
162162
if (auto FD = dyn_cast<AbstractFunctionDecl>(DC)) {
163-
if (FD->hasInterfaceType()) {
164-
auto Ty = FD->getInterfaceType();
165-
if (FD->getDeclContext()->isTypeContext())
166-
Ty = FD->getMethodInterfaceType();
167-
if (auto FT = Ty->getAs<AnyFunctionType>())
168-
return DC->mapTypeIntoContext(FT->getResult());
169-
}
163+
auto Ty = FD->getInterfaceType();
164+
if (FD->getDeclContext()->isTypeContext())
165+
Ty = FD->getMethodInterfaceType();
166+
if (auto FT = Ty->getAs<AnyFunctionType>())
167+
return DC->mapTypeIntoContext(FT->getResult());
170168
} else if (auto ACE = dyn_cast<AbstractClosureExpr>(DC)) {
171169
if (ACE->getType() && !ACE->getType()->hasError())
172170
return ACE->getResultType();
@@ -743,8 +741,7 @@ class ExprContextAnalyzer {
743741
if (!AFD)
744742
return;
745743
auto param = AFD->getParameters()->get(initDC->getIndex());
746-
if (param->hasInterfaceType())
747-
recordPossibleType(AFD->mapTypeIntoContext(param->getInterfaceType()));
744+
recordPossibleType(AFD->mapTypeIntoContext(param->getInterfaceType()));
748745
break;
749746
}
750747
}

lib/Sema/ConstraintSystem.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -825,11 +825,6 @@ Type ConstraintSystem::getUnopenedTypeOfReference(VarDecl *value, Type baseType,
825825
return getType(param);
826826

827827
if (!var->hasInterfaceType()) {
828-
if (!var->isInvalid()) {
829-
TC.diagnose(var->getLoc(), diag::recursive_decl_reference,
830-
var->getDescriptiveKind(), var->getName());
831-
var->setInvalid();
832-
}
833828
return ErrorType::get(TC.Context);
834829
}
835830

lib/Sema/TypeCheckDeclOverride.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,8 @@ OverrideMatcher::OverrideMatcher(ValueDecl *decl)
693693
// The final step for this constructor is to set up the superclass type,
694694
// without which we will not perform an matching. Early exits therefore imply
695695
// that there is no way we can match this declaration.
696-
if (decl->isInvalid())
696+
// FIXME: Break the cycle here.
697+
if (decl->hasInterfaceType() && decl->isInvalid())
697698
return;
698699

699700
auto *dc = decl->getDeclContext();

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -327,13 +327,13 @@ swift::matchWitness(
327327
if (req->getKind() != witness->getKind())
328328
return RequirementMatch(witness, MatchKind::KindConflict);
329329

330-
// If the witness is invalid, record that and stop now.
331-
if (witness->isInvalid())
332-
return RequirementMatch(witness, MatchKind::WitnessInvalid);
333-
334330
// If we're currently validating the witness, bail out.
335331
if (witness->isRecursiveValidation())
336332
return RequirementMatch(witness, MatchKind::Circularity);
333+
334+
// If the witness is invalid, record that and stop now.
335+
if (witness->isInvalid())
336+
return RequirementMatch(witness, MatchKind::WitnessInvalid);
337337

338338
// Get the requirement and witness attributes.
339339
const auto &reqAttrs = req->getAttrs();

test/Constraints/diagnostics.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ struct A : P2 {
8686
func wonka() {}
8787
}
8888
let a = A()
89-
for j in i.wibble(a, a) { // expected-error {{for-in loop requires 'A' to conform to 'Sequence'}} expected-error{{variable 'j' is not bound by any pattern}}
89+
for j in i.wibble(a, a) { // expected-error {{for-in loop requires 'A' to conform to 'Sequence'}}
9090
}
9191

9292
// Generic as part of function/tuple types

test/Constraints/members.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ struct S22490787 {
316316
func f22490787() {
317317
var path: S22490787 = S22490787()
318318

319-
for p in path { // expected-error {{for-in loop requires 'S22490787' to conform to 'Sequence'}} expected-error{{variable 'p' is not bound by any pattern}}
319+
for p in path { // expected-error {{for-in loop requires 'S22490787' to conform to 'Sequence'}}
320320
}
321321
}
322322

test/Constraints/patterns.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ switch staticMembers {
290290

291291
case .init(0): break
292292
case .init(_): break // expected-error{{'_' can only appear in a pattern}}
293-
case .init(let x): break // expected-error{{cannot appear in an expression}} expected-error{{variable 'x' is not bound by any pattern}}
293+
case .init(let x): break // expected-error{{cannot appear in an expression}}
294294
case .init(opt: 0): break // expected-error{{value of optional type 'StaticMembers?' must be unwrapped to a value of type 'StaticMembers'}}
295295
// expected-note@-1 {{force-unwrap using '!' to abort execution if the optional value contains 'nil'}}
296296
// expected-note@-2 {{coalesce using '??' to provide a default when the optional value contains 'nil'}}
@@ -302,12 +302,12 @@ switch staticMembers {
302302
case .method: break // expected-error{{cannot match}}
303303
case .method(0): break
304304
case .method(_): break // expected-error{{'_' can only appear in a pattern}}
305-
case .method(let x): break // expected-error{{cannot appear in an expression}} expected-error{{variable 'x' is not bound by any pattern}}
305+
case .method(let x): break // expected-error{{cannot appear in an expression}}
306306

307307
case .method(withLabel:): break // expected-error{{cannot match}}
308308
case .method(withLabel: 0): break
309309
case .method(withLabel: _): break // expected-error{{'_' can only appear in a pattern}}
310-
case .method(withLabel: let x): break // expected-error{{cannot appear in an expression}} expected-error{{variable 'x' is not bound by any pattern}}
310+
case .method(withLabel: let x): break // expected-error{{cannot appear in an expression}}
311311

312312
case .optMethod: break // expected-error{{cannot match}}
313313
case .optMethod(0): break

test/Generics/deduction.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ class DeducePropertyParams {
311311
// SR-69
312312
struct A {}
313313
func foo() {
314-
for i in min(1,2) { // expected-error{{for-in loop requires 'Int' to conform to 'Sequence'}} expected-error {{variable 'i' is not bound by any pattern}}
314+
for i in min(1,2) { // expected-error{{for-in loop requires 'Int' to conform to 'Sequence'}}
315315
}
316316
let j = min(Int(3), Float(2.5)) // expected-error{{cannot convert value of type 'Float' to expected argument type 'Int'}}
317317
let k = min(A(), A()) // expected-error{{global function 'min' requires that 'A' conform to 'Comparable'}}

test/IDE/complete_single_expression_return.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ struct TestSingleExprSubscriptGlobal {
556556

557557
// TestSingleExprSubscriptGlobal: Begin completions
558558
// TestSingleExprSubscriptGlobal-DAG: Decl[InstanceMethod]/CurrNominal: str()[#String#];
559-
// TestSingleExprSubscriptGlobal-DAG: Decl[InstanceMethod]/CurrNominal/TypeRelation[Identical]: int()[#Int#];
559+
// TestSingleExprSubscriptGlobal-DAG: Decl[InstanceMethod]/CurrNominal: int()[#Int#];
560560
// TestSingleExprSubscriptGlobal-DAG: Decl[InstanceMethod]/CurrNominal: void()[#Void#];
561561
// TestSingleExprSubscriptGlobal: End completions
562562
}

test/NameBinding/name_lookup.swift

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ class ThisDerived1 : ThisBase1 {
224224
self.baseProp = 42 // expected-error {{member 'baseProp' cannot be used on type 'ThisDerived1'}}
225225
self.baseFunc0() // expected-error {{instance member 'baseFunc0' cannot be used on type 'ThisDerived1'}}
226226
self.baseFunc0(ThisBase1())() // expected-error {{cannot convert value of type 'ThisBase1' to expected argument type 'ThisDerived1'}}
227-
227+
228228
self.baseFunc0(ThisDerived1())()
229229
self.baseFunc1(42) // expected-error {{instance member 'baseFunc1' cannot be used on type 'ThisDerived1'}}
230230
self.baseFunc1(ThisBase1())(42) // expected-error {{cannot convert value of type 'ThisBase1' to expected argument type 'ThisDerived1'}}
@@ -482,7 +482,7 @@ struct MyStruct {
482482
// <rdar://problem/19935319> QoI: poor diagnostic initializing a variable with a non-class func
483483
class Test19935319 {
484484
let i = getFoo() // expected-error {{cannot use instance member 'getFoo' within property initializer; property initializers run before 'self' is available}}
485-
485+
486486
func getFoo() -> Int {}
487487
}
488488

@@ -616,18 +616,21 @@ struct PatternBindingWithTwoVars1 { var x = 3, y = x }
616616
// expected-error@-1 {{cannot use instance member 'x' within property initializer; property initializers run before 'self' is available}}
617617

618618
struct PatternBindingWithTwoVars2 { var x = y, y = 3 }
619-
// expected-error@-1 {{property 'y' references itself}}
620-
// expected-error@-2 {{cannot use instance member 'y' within property initializer; property initializers run before 'self' is available}}
619+
// expected-error@-1 {{cannot use instance member 'y' within property initializer; property initializers run before 'self' is available}}
621620

622-
// This one should be accepted, but for now PatternBindingDecl validation
623-
// circularity detection is not fine grained enough.
624621
struct PatternBindingWithTwoVars3 { var x = y, y = x }
625622
// expected-error@-1 {{cannot use instance member 'x' within property initializer; property initializers run before 'self' is available}}
626623
// expected-error@-2 {{cannot use instance member 'y' within property initializer; property initializers run before 'self' is available}}
627-
// expected-error@-3 {{property 'y' references itself}}
624+
// expected-error@-3 {{circular reference}}
625+
// expected-note@-4 {{through reference here}}
626+
// expected-note@-5 {{through reference here}}
627+
// expected-note@-6 {{through reference here}}
628+
// expected-note@-7 {{through reference here}}
629+
// expected-note@-8 {{through reference here}}
630+
628631

629632
// https://bugs.swift.org/browse/SR-9015
630633
func sr9015() {
631-
let closure1 = { closure2() } // expected-error {{circular reference}} expected-error{{variable 'closure1' is not bound by any pattern}} expected-note {{through reference here}} expected-note {{through reference here}}
634+
let closure1 = { closure2() } // expected-error {{circular reference}} expected-note {{through reference here}} expected-note {{through reference here}}
632635
let closure2 = { closure1() } // expected-note {{through reference here}} expected-note {{through reference here}} expected-note {{through reference here}}
633636
}

test/Parse/EOF/unfinished-for-at-eof.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,4 @@ func fuzz() { for var H
55
// expected-error@-2{{expected Sequence expression for for-each loop}}
66
// expected-error@-3{{expected '{' to start the body of for-each loop}}
77
// expected-note@-4 {{to match this opening '{'}}
8-
// expected-error@-5 {{variable 'H' is not bound by any pattern}}
98
// expected-error@+1{{expected '}' at end of brace statement}}

test/Parse/enum_element_pattern_swift4.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ func testE(e: E) {
4343
// expected-note@-1 {{remove associated values to make the pattern match}} {{12-14=}}
4444
case .D(let payload) = e // expected-error {{pattern with associated values does not match enum case 'D'}}
4545
// expected-note@-1 {{remove associated values to make the pattern match}} {{12-25=}}
46-
// expected-error@-2 {{variable 'payload' is not bound by any pattern}}
4746
else { return }
4847
}
4948

test/Parse/foreach.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,5 @@ func for_each(r: Range<Int>, iir: IntRange<Int>) { // expected-note {{'r' declar
3636
// expected-note @-2 {{join the identifiers together with camel-case}}
3737
// expected-error @-3 {{expected 'in' after for-each pattern}}
3838
// expected-error @-4 {{expected Sequence expression for for-each loop}}
39-
// expected-error @-5 {{variable 'i' is not bound by any pattern}}
4039
for i in r sum = sum + i; // expected-error{{expected '{' to start the body of for-each loop}}
4140
}

test/Parse/matching_patterns.swift

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,8 @@ enum Voluntary<T> : Equatable {
118118
var n : Voluntary<Int> = .Naught
119119
if case let .Naught(value) = n {} // expected-error{{pattern with associated values does not match enum case 'Naught'}}
120120
// expected-note@-1 {{remove associated values to make the pattern match}} {{20-27=}}
121-
// expected-error@-2 {{variable 'value' is not bound by any pattern}}
122121
if case let .Naught(value1, value2, value3) = n {} // expected-error{{pattern with associated values does not match enum case 'Naught'}}
123122
// expected-note@-1 {{remove associated values to make the pattern match}} {{20-44=}}
124-
// expected-error@-2 {{variable 'value1' is not bound by any pattern}}
125123

126124

127125

@@ -284,12 +282,10 @@ case (1, 2, 3):
284282
case +++(_, var d, 3):
285283
// expected-error@-1{{'_' can only appear in a pattern or on the left side of an assignment}}
286284
// expected-error@-2{{'var' binding pattern cannot appear in an expression}}
287-
// expected-error@-3 {{variable 'd' is not bound by any pattern}}
288285
()
289286
case (_, var e, 3) +++ (1, 2, 3):
290287
// expected-error@-1{{'_' can only appear in a pattern}}
291288
// expected-error@-2{{'var' binding pattern cannot appear in an expression}}
292-
// expected-error@-3 {{variable 'e' is not bound by any pattern}}
293289
()
294290
case (let (_, _, _)) + 1:
295291
// expected-error@-1 2 {{'var' binding pattern cannot appear in an expression}}
@@ -305,7 +301,6 @@ class Derived : Base { }
305301

306302
switch [Derived(), Derived(), Base()] {
307303
case let ds as [Derived]: // expected-error{{collection downcast in cast pattern is not implemented; use an explicit downcast to '[Derived]' instead}}
308-
// expected-error@-1 {{variable 'ds' is not bound by any pattern}}
309304
()
310305
case is [Derived]: // expected-error{{collection downcast in cast pattern is not implemented; use an explicit downcast to '[Derived]' instead}}
311306
()

test/Parse/recovery.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ func missingControllingExprInFor() {
152152
for ; true { // expected-error {{C-style for statement has been removed in Swift 3}}
153153
}
154154

155-
for var i = 0; true { // expected-error {{C-style for statement has been removed in Swift 3}} expected-error{{variable 'i' is not bound by any pattern}}
155+
for var i = 0; true { // expected-error {{C-style for statement has been removed in Swift 3}}
156156
i += 1
157157
}
158158
}
@@ -174,13 +174,11 @@ func missingControllingExprInForEach() {
174174
{
175175
}
176176

177-
// expected-error @+3 {{variable 'i' is not bound by any pattern}}
178177
// expected-error @+2 {{expected 'in' after for-each pattern}}
179178
// expected-error @+1 {{expected Sequence expression for for-each loop}}
180179
for i {
181180
}
182181

183-
// expected-error @+3 {{variable 'i' is not bound by any pattern}}
184182
// expected-error @+2 {{expected 'in' after for-each pattern}}
185183
// expected-error @+1 {{expected Sequence expression for for-each loop}}
186184
for var i {
@@ -201,7 +199,6 @@ func missingControllingExprInForEach() {
201199
for for in {
202200
}
203201

204-
// expected-error @+1 {{variable 'i' is not bound by any pattern}}
205202
for i in { // expected-error {{expected Sequence expression for for-each loop}}
206203
}
207204

test/Parse/toplevel_library_invalid.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ x + x; // expected-error {{expressions are not allowed at the top level}} expect
1010
// expected-warning @-1 {{result of call to closure returning 'Int' is unused}}
1111

1212

13-
// expected-error @+4 {{variable 'i' is not bound by any pattern}}
1413
// expected-error @+3 {{expected 'in' after for-each pattern}}
1514
// expected-error @+2 {{expected Sequence expression for for-each loop}}
1615
// expected-error @+1 {{expected '{' to start the body of for-each loop}}

test/Sema/editor_placeholders.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ f(<#T##Int#>) // expected-error{{editor placeholder in source file}}
2727
f(<#T##String#>) // expected-error{{editor placeholder in source file}} expected-error{{cannot convert value of type 'String' to expected argument type 'Int'}}
2828

2929
for x in <#T#> { // expected-error{{editor placeholder in source file}} expected-error{{for-in loop requires '()' to conform to 'Sequence'}}
30-
// expected-error@-1{{variable 'x' is not bound by any pattern}}
30+
3131
}

test/SourceKit/Sema/placeholders.swift.placeholders.response

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,6 @@
1414
}
1515
]
1616
},
17-
{
18-
key.line: 4,
19-
key.column: 7,
20-
key.filepath: placeholders.swift,
21-
key.severity: source.diagnostic.severity.error,
22-
key.description: "variable '<#name#>' is not bound by any pattern",
23-
key.diagnostic_stage: source.diagnostic.stage.swift.sema
24-
},
2517
{
2618
key.line: 4,
2719
key.column: 19,

test/attr/attr_dynamic_member_lookup.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,6 @@ func keypath_with_incorrect_return_type(_ arr: Lens<Array<Int>>) {
604604
// expected-error@-2 {{protocol 'Sequence' requires that 'Lens<Int>.Stride' conform to 'SignedInteger'}}
605605
// expected-error@-3 {{cannot convert value of type 'Int' to expected argument type 'Lens<Int>'}}
606606
// expected-error@-4 {{referencing operator function '..<' on 'Comparable' requires that 'Lens<Int>' conform to 'Comparable'}}
607-
// expected-error@-5 {{variable 'idx' is not bound by any pattern}}
608607
let _ = arr[idx]
609608
}
610609
}

test/decl/var/variables.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,12 @@ class SomeClass {}
6666
weak let V = SomeClass() // expected-error {{'weak' must be a mutable variable, because it may change at runtime}}
6767

6868
let a = b ; let b = a
69-
// expected-error@-1 {{variable 'a' is not bound by any pattern}}
70-
// expected-error@-2 {{circular reference}}
69+
// expected-error@-1 {{circular reference}}
70+
// expected-note@-2 {{through reference here}}
7171
// expected-note@-3 {{through reference here}}
7272
// expected-note@-4 {{through reference here}}
7373
// expected-note@-5 {{through reference here}}
7474
// expected-note@-6 {{through reference here}}
75-
// expected-note@-7 {{through reference here}}
7675

7776
// <rdar://problem/17501765> Swift should warn about immutable default initialized values
7877
let uselessValue : String?

test/stmt/c_style_for.swift

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,27 @@
22

33
for var i = 0; i < 10; i++ {}
44
// expected-error @-1 {{C-style for statement has been removed in Swift 3}} {{none}}
5-
// expected-error @-2 {{variable 'i' is not bound by any pattern}}
65

76
for var i = 0; i < 10; i += 1 {}
87
// expected-error @-1 {{C-style for statement has been removed in Swift 3}} {{none}}
9-
// expected-error @-2 {{variable 'i' is not bound by any pattern}}
108

119
for var i = 0; i <= 10; i++ {}
1210
// expected-error @-1 {{C-style for statement has been removed in Swift 3}} {{none}}
13-
// expected-error @-2 {{variable 'i' is not bound by any pattern}}
1411

1512
for var i = 0; i <= 10; i += 1 {}
1613
// expected-error @-1 {{C-style for statement has been removed in Swift 3}} {{none}}
17-
// expected-error @-2 {{variable 'i' is not bound by any pattern}}
1814

1915
for var i = 10; i > 0; i-- {}
2016
// expected-error @-1 {{C-style for statement has been removed in Swift 3}} {{none}}
21-
// expected-error @-2 {{variable 'i' is not bound by any pattern}}
2217

2318
for var i = 10; i > 0; i -= 1 {}
2419
// expected-error @-1 {{C-style for statement has been removed in Swift 3}} {{none}}
25-
// expected-error @-2 {{variable 'i' is not bound by any pattern}}
2620

2721
for var i = 10; i >= 0; i-- {}
2822
// expected-error @-1 {{C-style for statement has been removed in Swift 3}} {{none}}
29-
// expected-error @-2 {{variable 'i' is not bound by any pattern}}
3023

3124
for var i = 10; i >= 0; i -= 1 {}
3225
// expected-error @-1 {{C-style for statement has been removed in Swift 3}} {{none}}
33-
// expected-error @-2 {{variable 'i' is not bound by any pattern}}
3426

3527
let start = Int8(4)
3628
let count = Int8(10)

0 commit comments

Comments
 (0)