Skip to content

Commit 6e773a0

Browse files
authored
Merge pull request #19199 from DougGregor/multifile-inherit-generic-init
[Type checker] Make sure we have a generic signature when inheriting initializers.
2 parents 4e68ecf + 8af269a commit 6e773a0

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

lib/Sema/TypeCheckDecl.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5536,6 +5536,8 @@ void TypeChecker::addImplicitConstructors(NominalTypeDecl *decl) {
55365536
}
55375537

55385538
// We have a designated initializer. Create an override of it.
5539+
// FIXME: Validation makes sure we get a generic signature here.
5540+
validateDecl(classDecl);
55395541
if (auto ctor = createDesignatedInitOverride(
55405542
*this, classDecl, superclassCtor, kind)) {
55415543
Context.addSynthesizedDecl(ctor);

lib/Sema/TypeCheckDeclOverride.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1106,7 +1106,7 @@ bool swift::checkOverrides(ValueDecl *decl) {
11061106
return false;
11071107
}
11081108

1109-
// Try to match with the
1109+
// Try to match with this attempt kind.
11101110
matches = matcher.match(attempt);
11111111
if (!matches.empty())
11121112
break;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class A {
2+
init(foo: Int) { }
3+
init(other: Int) { }
4+
}
5+
6+
7+
class B<T>: A { }

test/multifile/inherited-inits.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: %target-swift-frontend -typecheck -primary-file %s %S/Inputs/inherited-inits-other.swift -verify
2+
3+
// expected-no-diagnostics
4+
5+
// Test that we get the generic signature right (which is needed for the
6+
// super.init to properly type-check) when it comes from another source
7+
// file (rdar://problem/44235762).
8+
class C: B<Int> {
9+
override init(foo: Int) {
10+
super.init(foo: foo)
11+
}
12+
}

0 commit comments

Comments
 (0)