Don't synthesize initializers in swiftinterface files

...and then don't complain about a class not having any initializers.
This commit is contained in:
Jordan Rose
2018-08-16 17:57:18 -07:00
parent 0ca78265ef
commit c62fcad553
3 changed files with 27 additions and 2 deletions

View File

@@ -5481,6 +5481,8 @@ ParserResult<EnumDecl> Parser::parseDeclEnum(ParseDeclOptions Flags,
{ }, nullptr, CurDeclContext);
setLocalDiscriminator(ED);
ED->getAttrs() = Attributes;
if (SF.Kind == SourceFileKind::Interface)
ED->setAddedImplicitInitializers();
ContextChange CC(*this, ED);
@@ -5753,6 +5755,8 @@ ParserResult<StructDecl> Parser::parseDeclStruct(ParseDeclOptions Flags,
CurDeclContext);
setLocalDiscriminator(SD);
SD->getAttrs() = Attributes;
if (SF.Kind == SourceFileKind::Interface)
SD->setAddedImplicitInitializers();
ContextChange CC(*this, SD);
@@ -5840,9 +5844,9 @@ ParserResult<ClassDecl> Parser::parseDeclClass(ParseDeclOptions Flags,
ClassDecl *CD = new (Context) ClassDecl(ClassLoc, ClassName, ClassNameLoc,
{ }, nullptr, CurDeclContext);
setLocalDiscriminator(CD);
// Attach attributes.
CD->getAttrs() = Attributes;
if (SF.Kind == SourceFileKind::Interface)
CD->setAddedImplicitInitializers();
ContextChange CC(*this, CD);

View File

@@ -5138,6 +5138,19 @@ static void diagnoseClassWithoutInitializers(TypeChecker &tc,
}
void TypeChecker::maybeDiagnoseClassWithoutInitializers(ClassDecl *classDecl) {
if (auto *SF = classDecl->getParentSourceFile()) {
// Allow classes without initializers in SIL and textual interface files.
switch (SF->Kind) {
case SourceFileKind::SIL:
case SourceFileKind::Interface:
return;
case SourceFileKind::Library:
case SourceFileKind::Main:
case SourceFileKind::REPL:
break;
}
}
// Some heuristics to skip emitting a diagnostic if the class is already
// irreperably busted.
if (classDecl->isInvalid() ||

View File

@@ -29,6 +29,14 @@ public class TestClass {
deinit
} // CHECK: {{^}$}}
// CHECK-LABEL: public class TestEmptyClass {
public class TestEmptyClass {
} // CHECK-NEXT: {{^}$}}
// CHECK-LABEL: public struct TestEmptyStruct {
public struct TestEmptyStruct {
} // CHECK-NEXT: {{^}$}}
// CHECK-LABEL: public enum TestEnum
public enum TestEnum {
// CHECK: case a