Skip to content

Commit 02971fb

Browse files
committed
Merge pull request #432 from gregomni/sr-176
[SR-176] Skip type checking case patterns when switch is error type.
2 parents 92d2309 + 44a69d2 commit 02971fb

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

lib/Sema/TypeCheckPattern.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -1229,7 +1229,7 @@ bool TypeChecker::coercePatternToType(Pattern *&P, DeclContext *dc, Type type,
12291229
IP->getLoc(),
12301230
IP->getLoc(),IP->getCastTypeLoc().getSourceRange(),
12311231
[](Type) { return false; },
1232-
/*suppressDiagnostics=*/ false);
1232+
/*suppressDiagnostics=*/ type->is<ErrorType>());
12331233
switch (castKind) {
12341234
case CheckedCastKind::Unresolved:
12351235
return false;
@@ -1288,8 +1288,9 @@ bool TypeChecker::coercePatternToType(Pattern *&P, DeclContext *dc, Type type,
12881288
if (type->getAnyNominal())
12891289
elt = lookupEnumMemberElement(*this, dc, type, EEP->getName());
12901290
if (!elt) {
1291-
diagnose(EEP->getLoc(), diag::enum_element_pattern_member_not_found,
1292-
EEP->getName().str(), type);
1291+
if (!type->is<ErrorType>())
1292+
diagnose(EEP->getLoc(), diag::enum_element_pattern_member_not_found,
1293+
EEP->getName().str(), type);
12931294
return true;
12941295
}
12951296
enumTy = type;

test/Parse/recovery.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ func missingControllingExprInSwitch() {
228228
}
229229

230230
switch { // expected-error {{expected expression in 'switch' statement}}
231-
case Int: return // expected-error {{'is' keyword required to pattern match against type name}} {{10-10=is }} expected-warning {{cast from '<<error type>>' to unrelated type 'Int' always fails}}
231+
case Int: return // expected-error {{'is' keyword required to pattern match against type name}} {{10-10=is }}
232232
case _: return
233233
}
234234

test/Parse/switch.swift

+8
Original file line numberDiff line numberDiff line change
@@ -261,3 +261,11 @@ func enumElementSyntaxOnTuple() {
261261
}
262262
}
263263

264+
// sr-176
265+
enum Whatever { case Thing }
266+
func f0(values: [Whatever]) {
267+
switch value { // expected-error {{use of unresolved identifier 'value'}}
268+
case .Thing: // Ok. Don't emit diagnostics about enum case not found in type <<error type>>.
269+
break
270+
}
271+
}

0 commit comments

Comments
 (0)