@@ -258,34 +258,35 @@ PatternBindingEntryRequest::evaluate(Evaluator &eval,
258
258
}
259
259
for (auto *sv: vars) {
260
260
bool hasConst = sv->getAttrs ().getAttribute <CompileTimeConstAttr>();
261
- bool hasStatic = StaticSpelling != StaticSpellingKind::None;
262
261
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)) {
284
285
if (!init->isSemanticallyConstExpr ()) {
285
286
binding->diagnose (diag::require_const_initializer_for_const);
286
- break ;
287
287
}
288
- break ;
288
+ } else {
289
+ binding->diagnose (diag::require_const_initializer_for_const);
289
290
}
290
291
}
291
292
0 commit comments