Skip to content

Commit a9ee16e

Browse files
authored
Merge pull request #20119 from slavapestov/fix-some-crashers
Fix some crashers
2 parents b80991d + add4185 commit a9ee16e

File tree

5 files changed

+25
-15
lines changed

5 files changed

+25
-15
lines changed

lib/AST/GenericSignatureBuilder.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3875,6 +3875,12 @@ static Type resolveDependentMemberTypes(GenericSignatureBuilder &builder,
38753875
if (equivClass->recursiveConcreteType)
38763876
return ErrorType::get(Type(type));
38773877

3878+
// Prevent recursive substitution.
3879+
equivClass->recursiveConcreteType = true;
3880+
SWIFT_DEFER {
3881+
equivClass->recursiveConcreteType = false;
3882+
};
3883+
38783884
return resolveDependentMemberTypes(builder, equivClass->concreteType);
38793885
}
38803886

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+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// RUN: not %target-swift-frontend -typecheck %s
2+
3+
class Graph<V>: Collection {
4+
typealias Iterator = AnyIterator<V>
5+
typealias Index = Int
6+
}

0 commit comments

Comments
 (0)