Skip to content

[Type checker] Make sure we have a generic signature when inheriting initializers. #19199

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
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
2 changes: 2 additions & 0 deletions lib/Sema/TypeCheckDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5536,6 +5536,8 @@ void TypeChecker::addImplicitConstructors(NominalTypeDecl *decl) {
}

// We have a designated initializer. Create an override of it.
// FIXME: Validation makes sure we get a generic signature here.
validateDecl(classDecl);
if (auto ctor = createDesignatedInitOverride(
*this, classDecl, superclassCtor, kind)) {
Context.addSynthesizedDecl(ctor);
Expand Down
2 changes: 1 addition & 1 deletion lib/Sema/TypeCheckDeclOverride.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1106,7 +1106,7 @@ bool swift::checkOverrides(ValueDecl *decl) {
return false;
}

// Try to match with the
// Try to match with this attempt kind.
matches = matcher.match(attempt);
if (!matches.empty())
break;
Expand Down
7 changes: 7 additions & 0 deletions test/multifile/Inputs/inherited-inits-other.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class A {
init(foo: Int) { }
init(other: Int) { }
}


class B<T>: A { }
12 changes: 12 additions & 0 deletions test/multifile/inherited-inits.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// RUN: %target-swift-frontend -typecheck -primary-file %s %S/Inputs/inherited-inits-other.swift -verify

// expected-no-diagnostics

// Test that we get the generic signature right (which is needed for the
// super.init to properly type-check) when it comes from another source
// file (rdar://problem/44235762).
class C: B<Int> {
override init(foo: Int) {
super.init(foo: foo)
}
}