Skip to content

Fix some crashers #20119

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/AST/GenericSignatureBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3875,6 +3875,12 @@ static Type resolveDependentMemberTypes(GenericSignatureBuilder &builder,
if (equivClass->recursiveConcreteType)
return ErrorType::get(Type(type));

// Prevent recursive substitution.
equivClass->recursiveConcreteType = true;
SWIFT_DEFER {
equivClass->recursiveConcreteType = false;
};

return resolveDependentMemberTypes(builder, equivClass->concreteType);
}

Expand Down
17 changes: 2 additions & 15 deletions lib/Sema/TypeCheckDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3225,19 +3225,6 @@ class DeclChecker : public DeclVisitor<DeclChecker> {

TC.checkDeclAttributesEarly(ED);

if (auto extendedTy = ED->getExtendedType()) {
if (!extendedTy->is<NominalType>() &&
!extendedTy->is<BoundGenericType>() &&
!extendedTy->hasError()) {
// FIXME: Redundant diagnostic test here?
TC.diagnose(ED->getStartLoc(), diag::non_nominal_extension,
extendedTy);
// FIXME: It would be nice to point out where we found the named type
// declaration, if any.
ED->setInvalid();
}
}

checkInheritanceClause(ED);

if (auto nominal = ED->getExtendedNominal()) {
Expand Down Expand Up @@ -3273,8 +3260,8 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
// nominal type.
// FIXME: This is a hack to make sure that the type checker precomputes
// enough information for later passes that might query conformances.
if (auto nominal = ED->getSelfNominalTypeDecl())
(void)nominal->getAllConformances();
if (auto nominal = ED->getExtendedNominal())
(void) nominal->getAllConformances();
}

void visitTopLevelCodeDecl(TopLevelCodeDecl *TLCD) {
Expand Down
3 changes: 3 additions & 0 deletions lib/Sema/TypeCheckType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ Type TypeResolution::resolveDependentMemberType(
}

assert(stage == TypeResolutionStage::Interface);
if (!getGenericSignature())
return ErrorType::get(baseTy);

auto builder = getGenericSignatureBuilder();
auto baseEquivClass =
builder->resolveEquivalenceClass(
Expand Down
8 changes: 8 additions & 0 deletions test/decl/ext/generic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,11 @@ public typealias Array2 = Array
extension Array2 where QQQ : VVV {}
// expected-error@-1 {{use of undeclared type 'QQQ'}}
// expected-error@-2 {{use of undeclared type 'VVV'}}

// https://bugs.swift.org/browse/SR-9009
func foo() {
extension Array where Element : P1 {
// expected-error@-1 {{declaration is only valid at file scope}}
func foo() -> Element.AssocType {}
}
}
6 changes: 6 additions & 0 deletions validation-test/compiler_crashers_2_fixed/0180-sr9022.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// RUN: not %target-swift-frontend -typecheck %s

class Graph<V>: Collection {
typealias Iterator = AnyIterator<V>
typealias Index = Int
}