Skip to content

Commit 3115398

Browse files
committed
[AST] Fix crash in 'getOverrideGenericSignature()' when there are no generic params in the GSB
1 parent 7e86212 commit 3115398

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

lib/AST/ASTContext.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4398,6 +4398,7 @@ GenericSignature *
43984398
ASTContext::getOverrideGenericSignature(const ValueDecl *base,
43994399
const ValueDecl *derived) {
44004400
auto baseGenericCtx = base->getAsGenericContext();
4401+
auto derivedGenericCtx = derived->getAsGenericContext();
44014402
auto &ctx = base->getASTContext();
44024403

44034404
if (!baseGenericCtx) {
@@ -4421,6 +4422,10 @@ ASTContext::getOverrideGenericSignature(const ValueDecl *base,
44214422
return nullptr;
44224423
}
44234424

4425+
if (!derivedGenericCtx || !derivedGenericCtx->isGeneric()) {
4426+
return nullptr;
4427+
}
4428+
44244429
if (derivedClass->getGenericSignature() == nullptr &&
44254430
!baseGenericCtx->isGeneric()) {
44264431
return nullptr;
@@ -4449,12 +4454,8 @@ ASTContext::getOverrideGenericSignature(const ValueDecl *base,
44494454
GenericSignatureBuilder builder(ctx);
44504455
builder.addGenericSignature(derivedClass->getGenericSignature());
44514456

4452-
if (auto derivedGenericCtx = derived->getAsGenericContext()) {
4453-
if (derivedGenericCtx->isGeneric()) {
4454-
for (auto param : *derivedGenericCtx->getGenericParams()) {
4455-
builder.addGenericParameter(param);
4456-
}
4457-
}
4457+
for (auto param : *derivedGenericCtx->getGenericParams()) {
4458+
builder.addGenericParameter(param);
44584459
}
44594460

44604461
auto source =

test/attr/attr_override.swift

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,23 @@ class SR_10198_Base {
606606
}
607607

608608
class SR_10198_Derived: SR_10198_Base {
609-
override func a<T>(_ val: T) -> String { return super.a(val) }
610-
override func a<T: Equatable>(_ val: T) -> String { return super.a(val) }
609+
override func a<T>(_ val: T) -> String { return super.a(val) } // okay
610+
override func a<T: Equatable>(_ val: T) -> String { return super.a(val) } // okay
611611
}
612+
613+
protocol SR_10198_Base_P {
614+
associatedtype Bar
615+
}
616+
617+
struct SR_10198_Base_S: SR_10198_Base_P {
618+
typealias Bar = Int
619+
}
620+
621+
class SR_10198_Base_1 {
622+
init<F: SR_10198_Base_P>(_ arg: F) where F.Bar == Int {}
623+
}
624+
625+
class SR_10198_Derived_1: SR_10198_Base_1 {
626+
init(_ arg1: Int) { super.init(SR_10198_Base_S()) } // okay, doesn't crash
627+
}
628+

0 commit comments

Comments
 (0)