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'}}

0 commit comments

Comments
 (0)