From c62fcad5531f0708a9995dde7df7fdac815d102e Mon Sep 17 00:00:00 2001 From: Jordan Rose Date: Thu, 16 Aug 2018 17:57:18 -0700 Subject: [PATCH] Don't synthesize initializers in swiftinterface files ...and then don't complain about a class not having any initializers. --- lib/Parse/ParseDecl.cpp | 8 ++++++-- lib/Sema/TypeCheckDecl.cpp | 13 +++++++++++++ test/ModuleInterface/SmokeTest.swiftinterface | 8 ++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp index fa1bd129979..1135428bbdb 100644 --- a/lib/Parse/ParseDecl.cpp +++ b/lib/Parse/ParseDecl.cpp @@ -5481,6 +5481,8 @@ ParserResult 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 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 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); diff --git a/lib/Sema/TypeCheckDecl.cpp b/lib/Sema/TypeCheckDecl.cpp index 7855d6bb807..70e03faada8 100644 --- a/lib/Sema/TypeCheckDecl.cpp +++ b/lib/Sema/TypeCheckDecl.cpp @@ -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() || diff --git a/test/ModuleInterface/SmokeTest.swiftinterface b/test/ModuleInterface/SmokeTest.swiftinterface index f30dd1d4b8d..43c4d3ce6de 100644 --- a/test/ModuleInterface/SmokeTest.swiftinterface +++ b/test/ModuleInterface/SmokeTest.swiftinterface @@ -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