Skip to content

Commit c62fcad

Browse files
committed
Don't synthesize initializers in swiftinterface files
...and then don't complain about a class not having any initializers.
1 parent 0ca7826 commit c62fcad

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

lib/Parse/ParseDecl.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5481,6 +5481,8 @@ ParserResult<EnumDecl> Parser::parseDeclEnum(ParseDeclOptions Flags,
54815481
{ }, nullptr, CurDeclContext);
54825482
setLocalDiscriminator(ED);
54835483
ED->getAttrs() = Attributes;
5484+
if (SF.Kind == SourceFileKind::Interface)
5485+
ED->setAddedImplicitInitializers();
54845486

54855487
ContextChange CC(*this, ED);
54865488

@@ -5753,6 +5755,8 @@ ParserResult<StructDecl> Parser::parseDeclStruct(ParseDeclOptions Flags,
57535755
CurDeclContext);
57545756
setLocalDiscriminator(SD);
57555757
SD->getAttrs() = Attributes;
5758+
if (SF.Kind == SourceFileKind::Interface)
5759+
SD->setAddedImplicitInitializers();
57565760

57575761
ContextChange CC(*this, SD);
57585762

@@ -5840,9 +5844,9 @@ ParserResult<ClassDecl> Parser::parseDeclClass(ParseDeclOptions Flags,
58405844
ClassDecl *CD = new (Context) ClassDecl(ClassLoc, ClassName, ClassNameLoc,
58415845
{ }, nullptr, CurDeclContext);
58425846
setLocalDiscriminator(CD);
5843-
5844-
// Attach attributes.
58455847
CD->getAttrs() = Attributes;
5848+
if (SF.Kind == SourceFileKind::Interface)
5849+
CD->setAddedImplicitInitializers();
58465850

58475851
ContextChange CC(*this, CD);
58485852

lib/Sema/TypeCheckDecl.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5138,6 +5138,19 @@ static void diagnoseClassWithoutInitializers(TypeChecker &tc,
51385138
}
51395139

51405140
void TypeChecker::maybeDiagnoseClassWithoutInitializers(ClassDecl *classDecl) {
5141+
if (auto *SF = classDecl->getParentSourceFile()) {
5142+
// Allow classes without initializers in SIL and textual interface files.
5143+
switch (SF->Kind) {
5144+
case SourceFileKind::SIL:
5145+
case SourceFileKind::Interface:
5146+
return;
5147+
case SourceFileKind::Library:
5148+
case SourceFileKind::Main:
5149+
case SourceFileKind::REPL:
5150+
break;
5151+
}
5152+
}
5153+
51415154
// Some heuristics to skip emitting a diagnostic if the class is already
51425155
// irreperably busted.
51435156
if (classDecl->isInvalid() ||

test/ModuleInterface/SmokeTest.swiftinterface

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ public class TestClass {
2929
deinit
3030
} // CHECK: {{^}$}}
3131

32+
// CHECK-LABEL: public class TestEmptyClass {
33+
public class TestEmptyClass {
34+
} // CHECK-NEXT: {{^}$}}
35+
36+
// CHECK-LABEL: public struct TestEmptyStruct {
37+
public struct TestEmptyStruct {
38+
} // CHECK-NEXT: {{^}$}}
39+
3240
// CHECK-LABEL: public enum TestEnum
3341
public enum TestEnum {
3442
// CHECK: case a

0 commit comments

Comments
 (0)