Skip to content

Commit ad3588e

Browse files
committed
sema: avoid emitting several _const diagnostics for .swiftinterface files
1 parent 337b93f commit ad3588e

File tree

2 files changed

+27
-26
lines changed

2 files changed

+27
-26
lines changed

lib/Sema/TypeCheckStorage.cpp

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -258,34 +258,35 @@ PatternBindingEntryRequest::evaluate(Evaluator &eval,
258258
}
259259
for (auto *sv: vars) {
260260
bool hasConst = sv->getAttrs().getAttribute<CompileTimeConstAttr>();
261-
bool hasStatic = StaticSpelling != StaticSpellingKind::None;
262261
if (!hasConst)
263-
break;
264-
while(1) {
265-
// only static _const let/var is supported
266-
if (!hasStatic) {
267-
binding->diagnose(diag::require_static_for_const);
268-
break;
269-
}
270-
if (isReq) {
271-
break;
272-
}
273-
// var is only allowed in a protocol.
274-
if (!sv->isLet()) {
275-
binding->diagnose(diag::require_let_for_const);
276-
break;
277-
}
278-
// Diagnose when an init isn't given and it's not a compile-time constant
279-
auto *init = binding->getInit(entryNumber);
280-
if (!init) {
281-
binding->diagnose(diag::require_const_initializer_for_const);
282-
break;
283-
}
262+
continue;
263+
bool hasStatic = StaticSpelling != StaticSpellingKind::None;
264+
// only static _const let/var is supported
265+
if (!hasStatic) {
266+
binding->diagnose(diag::require_static_for_const);
267+
continue;
268+
}
269+
if (isReq) {
270+
continue;
271+
}
272+
auto varSourceFile = binding->getDeclContext()->getParentSourceFile();
273+
auto isVarInInterfaceFile =
274+
varSourceFile && varSourceFile->Kind == SourceFileKind::Interface;
275+
// Don't diagnose too strictly for textual interfaces.
276+
if (isVarInInterfaceFile) {
277+
continue;
278+
}
279+
// var is only allowed in a protocol.
280+
if (!sv->isLet()) {
281+
binding->diagnose(diag::require_let_for_const);
282+
}
283+
// Diagnose when an init isn't given and it's not a compile-time constant
284+
if (auto *init = binding->getInit(entryNumber)) {
284285
if (!init->isSemanticallyConstExpr()) {
285286
binding->diagnose(diag::require_const_initializer_for_const);
286-
break;
287287
}
288-
break;
288+
} else {
289+
binding->diagnose(diag::require_const_initializer_for_const);
289290
}
290291
}
291292

test/ModuleInterface/ConstKeyword.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
// RUN: %FileCheck %s < %t/printed-module.txt
1010

1111
public struct A {
12-
public _const let A = "value"
12+
public static _const let A = "value"
1313
public func takeConst1(a: _const Int) {}
1414
public func takeConst2(a b: _const Int) {}
1515
}
1616

17-
// CHECK: _const public let A: Swift.String
17+
// CHECK: _const public static let A: Swift.String
1818
// CHECK: public func takeConst1(a: _const Swift.Int)
1919
// CHECK: public func takeConst2(a b: _const Swift.Int)

0 commit comments

Comments
 (0)