[SILGen] Also handle initializers without bodies

I was surprised to see this parses fine already, but SILGen still
needs a new check.
This commit is contained in:
Jordan Rose
2018-08-16 13:46:40 -07:00
parent ed51d2255c
commit e2a245d211
2 changed files with 22 additions and 11 deletions

View File

@@ -776,9 +776,9 @@ void SILGenModule::emitConstructor(ConstructorDecl *decl) {
postEmitFunction(constant, f);
});
// If this constructor was imported, we don't need the initializing
// constructor to be emitted.
if (!decl->hasClangNode()) {
// Constructors may not have bodies if they've been imported, or if they've
// been parsed from a textual interface.
if (decl->hasBody()) {
SILDeclRef initConstant(decl, SILDeclRef::Kind::Initializer);
emitOrDelayFunction(
*this, initConstant,
@@ -796,14 +796,16 @@ void SILGenModule::emitConstructor(ConstructorDecl *decl) {
}
} else {
// Struct and enum constructors do everything in a single function.
emitOrDelayFunction(
*this, constant, [this, constant, decl, declCtx](SILFunction *f) {
preEmitFunction(constant, decl, f, decl);
PrettyStackTraceSILFunction X("silgen emitConstructor", f);
f->setProfiler(getOrCreateProfilerForConstructors(declCtx, decl));
SILGenFunction(*this, *f, decl).emitValueConstructor(decl);
postEmitFunction(constant, f);
});
if (decl->hasBody()) {
emitOrDelayFunction(
*this, constant, [this, constant, decl, declCtx](SILFunction *f) {
preEmitFunction(constant, decl, f, decl);
PrettyStackTraceSILFunction X("silgen emitConstructor", f);
f->setProfiler(getOrCreateProfilerForConstructors(declCtx, decl));
SILGenFunction(*this, *f, decl).emitValueConstructor(decl);
postEmitFunction(constant, f);
});
}
}
}

View File

@@ -10,6 +10,15 @@
// CHECK-LABEL: public class Test
public class Test {
// CHECK: public init(){{$}}
public init()
// CHECK: public func method(){{$}}
public func method()
// CHECK: public subscript(_: Int) -> Void{{$}}
public subscript(_: Int) -> Void { get set }
// NEGATIVE-NOT: deinit
deinit
} // CHECK: {{^}$}}