Skip to content

Commit 60ca648

Browse files
authored
Merge pull request #42408 from tshortli/dont-require-initial-values-in-interfaces
Sema: Don't require properties to have initializers in classes in module interfaces
2 parents f339fdc + 826cc9d commit 60ca648

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

lib/Sema/TypeCheckDeclPrimary.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2441,6 +2441,12 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
24412441

24422442
/// Check that all stored properties have in-class initializers.
24432443
void checkRequiredInClassInits(ClassDecl *cd) {
2444+
// Initializers may be omitted from property declarations in module
2445+
// interface files so don't diagnose in them.
2446+
SourceFile *sourceFile = cd->getDeclContext()->getParentSourceFile();
2447+
if (sourceFile && sourceFile->Kind == SourceFileKind::Interface)
2448+
return;
2449+
24442450
ClassDecl *source = nullptr;
24452451
for (auto member : cd->getMembers()) {
24462452
auto pbd = dyn_cast<PatternBindingDecl>(member);
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: %target-swift-emit-module-interface(%t.swiftinterface) %s
2+
// RUN: %target-swift-typecheck-module-from-interface(%t.swiftinterface)
3+
// RUN: %FileCheck %s < %t.swiftinterface
4+
5+
// CHECK: @requires_stored_property_inits public class RequiresStoredPropertyInits
6+
@requires_stored_property_inits
7+
public class RequiresStoredPropertyInits {
8+
// CHECK: final public let a: Swift.Int{{$}}
9+
public let a: Int = 0
10+
11+
public init() {}
12+
}

0 commit comments

Comments
 (0)