Skip to content

Commit 35518d7

Browse files
authored
Merge pull request #27857 from slavapestov/tiny-circularity-fixes
A couple of small circularity fixes
2 parents 2f34df9 + 79ef0b7 commit 35518d7

File tree

4 files changed

+41
-4
lines changed

4 files changed

+41
-4
lines changed

lib/AST/Type.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3572,8 +3572,6 @@ TypeBase::getContextSubstitutions(const DeclContext *dc,
35723572
if (auto *ownerClass = dyn_cast<ClassDecl>(ownerNominal))
35733573
baseTy = baseTy->getSuperclassForDecl(ownerClass);
35743574

3575-
assert(ownerNominal == baseTy->getAnyNominal());
3576-
35773575
// Gather all of the substitutions for all levels of generic arguments.
35783576
auto genericSig = dc->getGenericSignatureOfContext();
35793577
if (!genericSig)
@@ -3583,6 +3581,9 @@ TypeBase::getContextSubstitutions(const DeclContext *dc,
35833581
unsigned n = params.size();
35843582

35853583
while (baseTy && n > 0) {
3584+
if (baseTy->is<ErrorType>())
3585+
break;
3586+
35863587
// For a bound generic type, gather the generic parameter -> generic
35873588
// argument substitutions.
35883589
if (auto boundGeneric = baseTy->getAs<BoundGenericType>()) {

lib/Sema/TypeCheckDeclOverride.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,16 @@ Type swift::getMemberTypeForComparison(ASTContext &ctx, ValueDecl *member,
7777
SubscriptDecl *subscript = dyn_cast_or_null<SubscriptDecl>(abstractStorage);
7878

7979
auto memberType = member->getInterfaceType();
80+
if (memberType->is<ErrorType>())
81+
return memberType;
82+
8083
if (derivedDecl) {
8184
auto *dc = derivedDecl->getDeclContext();
8285
auto owningType = dc->getDeclaredInterfaceType();
8386
assert(owningType);
8487

8588
memberType = owningType->adjustSuperclassMemberDeclType(member, derivedDecl,
8689
memberType);
87-
if (memberType->hasError())
88-
return memberType;
8990
}
9091

9192
if (method) {

test/SILGen/default_arguments.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,3 +383,9 @@ func stupidGames(x: Int = 3) -> Int {
383383
return x
384384
}
385385
stupidGames(x:)()
386+
387+
func genericMagic<T : ExpressibleByStringLiteral>(x: T = #file) -> T {
388+
return x
389+
}
390+
391+
let _: String = genericMagic()

test/decl/circularity.swift

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,32 @@ extension SIMD3 {
5555
extension SIMD3 where SIMD3.Scalar == Float {
5656
static let pickMe = SIMD3(.pickMe)
5757
}
58+
59+
// Test case with circular overrides
60+
protocol P {
61+
associatedtype A
62+
// expected-note@-1 {{protocol requires nested type 'A'; do you want to add it?}}
63+
func run(a: A)
64+
}
65+
66+
class C1 {
67+
func run(a: Int) {}
68+
}
69+
70+
class C2: C1, P {
71+
override func run(a: A) {}
72+
// expected-error@-1 {{circular reference}}
73+
// expected-note@-2 2{{through reference here}}
74+
}
75+
76+
// Another crash to the above
77+
open class G1<A> {
78+
open func run(a: A) {}
79+
}
80+
81+
class C3: G1<A>, P {
82+
// expected-error@-1 {{type 'C3' does not conform to protocol 'P'}}
83+
// expected-error@-2 {{use of undeclared type 'A'}}
84+
override func run(a: A) {}
85+
// expected-error@-1 {{method does not override any method from its superclass}}
86+
}

0 commit comments

Comments
 (0)