Skip to content

Commit 95b30b8

Browse files
committed
---
yaml --- r: 349342 b: refs/heads/master-next c: 7be53c2 h: refs/heads/master
1 parent dfb3419 commit 95b30b8

File tree

4 files changed

+53
-7
lines changed

4 files changed

+53
-7
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
refs/heads/master: 3574c513bbc5578dd9346b4ea9ab5995c5927bb5
3-
refs/heads/master-next: 10f7b2df92bbc6c41f195bdcef92b301fa2b4a18
3+
refs/heads/master-next: 7be53c233d87541da11cd037eb74d847267e52a9
44
refs/tags/osx-passed: b6b74147ef8a386f532cf9357a1bde006e552c54
55
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-a: 6bb18e013c2284f2b45f5f84f2df2887dc0f7dea
66
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-b: 66d897bfcf64a82cb9a87f5e663d889189d06d07

branches/master-next/lib/AST/ASTContext.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4408,6 +4408,7 @@ GenericSignature *
44084408
ASTContext::getOverrideGenericSignature(const ValueDecl *base,
44094409
const ValueDecl *derived) {
44104410
auto baseGenericCtx = base->getAsGenericContext();
4411+
auto derivedGenericCtx = derived->getAsGenericContext();
44114412
auto &ctx = base->getASTContext();
44124413

44134414
if (!baseGenericCtx) {
@@ -4431,6 +4432,10 @@ ASTContext::getOverrideGenericSignature(const ValueDecl *base,
44314432
return nullptr;
44324433
}
44334434

4435+
if (!derivedGenericCtx || !derivedGenericCtx->isGeneric()) {
4436+
return nullptr;
4437+
}
4438+
44344439
if (derivedClass->getGenericSignature() == nullptr &&
44354440
!baseGenericCtx->isGeneric()) {
44364441
return nullptr;
@@ -4459,12 +4464,8 @@ ASTContext::getOverrideGenericSignature(const ValueDecl *base,
44594464
GenericSignatureBuilder builder(ctx);
44604465
builder.addGenericSignature(derivedClass->getGenericSignature());
44614466

4462-
if (auto derivedGenericCtx = derived->getAsGenericContext()) {
4463-
if (derivedGenericCtx->isGeneric()) {
4464-
for (auto param : *derivedGenericCtx->getGenericParams()) {
4465-
builder.addGenericParameter(param);
4466-
}
4467-
}
4467+
for (auto param : *derivedGenericCtx->getGenericParams()) {
4468+
builder.addGenericParameter(param);
44684469
}
44694470

44704471
auto source =

branches/master-next/lib/Sema/TypeCheckDeclOverride.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,22 @@ bool swift::isOverrideBasedOnType(ValueDecl *decl, Type declTy,
171171
if (declIUOAttr != parentDeclIUOAttr)
172172
return false;
173173

174+
// If the generic signatures don't match, then return false because we don't
175+
// want to complain if an overridden method matches multiple superclass
176+
// methods which differ in generic signature.
177+
//
178+
// We can still succeed with a subtype match later in
179+
// OverrideMatcher::match().
180+
auto declGenericCtx = decl->getAsGenericContext();
181+
auto &ctx = decl->getASTContext();
182+
auto sig = ctx.getOverrideGenericSignature(parentDecl, decl);
183+
184+
if (sig && declGenericCtx &&
185+
declGenericCtx->getGenericSignature()->getCanonicalSignature() !=
186+
sig->getCanonicalSignature()) {
187+
return false;
188+
}
189+
174190
// If this is a constructor, let's compare only parameter types.
175191
if (isa<ConstructorDecl>(decl)) {
176192
// Within a protocol context, check for a failability mismatch.

branches/master-next/test/attr/attr_override.swift

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,3 +597,32 @@ class SR_4206_Derived<C: SR_4206_Container> : SR_4206_Base<C.Key> {
597597
typealias Key = C.Key
598598
override func foo(forKey key: Key) throws {} // Okay, no generic signature mismatch
599599
}
600+
601+
// SR-10198
602+
603+
class SR_10198_Base {
604+
func a<T>(_ val: T) -> String { return "not equatable" }
605+
func a<T: Equatable>(_ val: T) -> String { return "equatable" }
606+
}
607+
608+
class SR_10198_Derived: SR_10198_Base {
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
611+
}
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)