mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Don't synthesize initializers in swiftinterface files
...and then don't complain about a class not having any initializers.
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
@@ -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() ||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user