Skip to content

Commit 6afb81d

Browse files
committed
Sema: Fix another crash with an invalid extension
Perhaps we should refactor everything so that extensions that are not at the top-level are still bound and type checked normally. However that requires a bit of work, so keep playing wack-a-mole for now to handle these invalid states when they come up. However while we're at it, make the code a little better by removing a bogus diagnostic path that was not used. Fixes <rdar://problem/45290211>, <https://bugs.swift.org/browse/SR-9009>.
1 parent ecf29e6 commit 6afb81d

File tree

3 files changed

+13
-15
lines changed

3 files changed

+13
-15
lines changed

lib/Sema/TypeCheckDecl.cpp

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3225,19 +3225,6 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
32253225

32263226
TC.checkDeclAttributesEarly(ED);
32273227

3228-
if (auto extendedTy = ED->getExtendedType()) {
3229-
if (!extendedTy->is<NominalType>() &&
3230-
!extendedTy->is<BoundGenericType>() &&
3231-
!extendedTy->hasError()) {
3232-
// FIXME: Redundant diagnostic test here?
3233-
TC.diagnose(ED->getStartLoc(), diag::non_nominal_extension,
3234-
extendedTy);
3235-
// FIXME: It would be nice to point out where we found the named type
3236-
// declaration, if any.
3237-
ED->setInvalid();
3238-
}
3239-
}
3240-
32413228
checkInheritanceClause(ED);
32423229

32433230
if (auto nominal = ED->getExtendedNominal()) {
@@ -3273,8 +3260,8 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
32733260
// nominal type.
32743261
// FIXME: This is a hack to make sure that the type checker precomputes
32753262
// enough information for later passes that might query conformances.
3276-
if (auto nominal = ED->getSelfNominalTypeDecl())
3277-
(void)nominal->getAllConformances();
3263+
if (auto nominal = ED->getExtendedNominal())
3264+
(void) nominal->getAllConformances();
32783265
}
32793266

32803267
void visitTopLevelCodeDecl(TopLevelCodeDecl *TLCD) {

lib/Sema/TypeCheckType.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,9 @@ Type TypeResolution::resolveDependentMemberType(
149149
}
150150

151151
assert(stage == TypeResolutionStage::Interface);
152+
if (!getGenericSignature())
153+
return ErrorType::get(baseTy);
154+
152155
auto builder = getGenericSignatureBuilder();
153156
auto baseEquivClass =
154157
builder->resolveEquivalenceClass(

test/decl/ext/generic.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,3 +167,11 @@ public typealias Array2 = Array
167167
extension Array2 where QQQ : VVV {}
168168
// expected-error@-1 {{use of undeclared type 'QQQ'}}
169169
// expected-error@-2 {{use of undeclared type 'VVV'}}
170+
171+
// https://bugs.swift.org/browse/SR-9009
172+
func foo() {
173+
extension Array where Element : P1 {
174+
// expected-error@-1 {{declaration is only valid at file scope}}
175+
func foo() -> Element.AssocType {}
176+
}
177+
}

0 commit comments

Comments
 (0)