Skip to content

Commit 79e8a6c

Browse files
committed
[Sema] Avoid marking TypeRepr invalid with SilenceErrors
Pattern resolution currently invokes type resolution with this flag since it's trying to see if it can treat a given expression as a TypeRepr for e.g an enum pattern. Make sure we don't `setInvalid` on such TypeRepr nodes since that will avoid diagnosing in cases where the node also then gets treated as a TypeRepr for an ExprPattern, where we actually want the diagnostic emitted.
1 parent 7296c82 commit 79e8a6c

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

lib/Sema/TypeCheckType.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2637,10 +2637,12 @@ static Type evaluateTypeResolution(const TypeResolution *resolution,
26372637
TypeResolver(*resolution, silContext)
26382638
.resolveType(TyR, resolution->getOptions());
26392639

2640-
// If we resolved down to an error, make sure to mark the typeRepr as invalid
2641-
// so we don't produce a redundant diagnostic.
2640+
// If we resolved down to an error, and we haven't silenced diagnostics, make
2641+
// sure to mark the typeRepr as invalid so we don't produce a redundant
2642+
// diagnostic.
26422643
if (result->hasError()) {
2643-
TyR->setInvalid();
2644+
if (!options.contains(TypeResolutionFlags::SilenceErrors))
2645+
TyR->setInvalid();
26442646
return result;
26452647
}
26462648

test/Constraints/patterns.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -820,3 +820,17 @@ do {
820820
}
821821
}
822822
}
823+
824+
// Make sure we diagnose 'Undefined' here.
825+
func testUndefinedTypeInPattern(_ x: Int) {
826+
switch x {
827+
case Optional<Undefined>.alsoUndefined: // expected-error {{cannot find type 'Undefined' in scope}}
828+
break
829+
}
830+
_ = {
831+
switch x {
832+
case Optional<Undefined>.alsoUndefined: // expected-error {{cannot find type 'Undefined' in scope}}
833+
break
834+
}
835+
}
836+
}

validation-test/compiler_crashers_2/75d8fd688b445bb.swift renamed to validation-test/compiler_crashers_2_fixed/75d8fd688b445bb.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// {"kind":"typecheck","original":"b7a10f72","signature":"(anonymous namespace)::Verifier::walkToExprPre(swift::Expr*)","signatureAssert":"Assertion failed: ((HadError || !isa<SourceFile *>(M) || cast<SourceFile *>(M)->ASTStage < SourceFile::TypeChecked) && \"OverloadedDeclRef\" \"in wrong phase\"), function walkToExprPre"}
2-
// RUN: not --crash %target-swift-frontend -typecheck %s
2+
// RUN: not %target-swift-frontend -typecheck %s
33
func a(b : Int) {
44
_ = {
55
switch b {

0 commit comments

Comments
 (0)