Skip to content

Commit 6615e16

Browse files
committed
AST: Skip stub initializers when printing module interfaces
When a derived class does not inherit a designated initializer from its base class, we override the designated initializer's vtable entry with a stub which traps with a fatal error. The stub cannot be called and clients do not need to be aware of its existence, so don't print it at all in the module interface. Fixes rdar://problem/71122015 / https://bugs.swift.org/browse/SR-13832.
1 parent 4769f21 commit 6615e16

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

lib/AST/ASTPrinter.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,12 @@ PrintOptions PrintOptions::printSwiftInterfaceFile(ModuleDecl *ModuleToPrint,
238238
}
239239
}
240240

241+
// Skip stub constructors.
242+
if (auto *ctor = dyn_cast<ConstructorDecl>(D)) {
243+
if (ctor->hasStubImplementation())
244+
return false;
245+
}
246+
241247
return ShouldPrintChecker::shouldPrint(D, options);
242248
}
243249
};

test/ModuleInterface/stub-init.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// RUN: %target-swift-frontend -typecheck -swift-version 5 -emit-module-interface-path - -module-name test %s | %FileCheck %s
2+
3+
public class Base {
4+
public init(x: Int) {}
5+
}
6+
7+
public class Derived: Base {
8+
public init(z: Int) {
9+
super.init(x: z)
10+
}
11+
}
12+
13+
// CHECK-LABEL: public class Base {
14+
// CHECK-NEXT: public init(x: Swift.Int)
15+
// CHECK-NEXT: {{(@objc )?}}deinit
16+
// CHECK-NEXT: }
17+
18+
// CHECK-LABEL: public class Derived : test.Base {
19+
// CHECK-NEXT: public init(z: Swift.Int)
20+
// CHECK-NEXT: {{(@objc )?}}deinit
21+
// CHECK-NEXT: }
22+

0 commit comments

Comments
 (0)