Skip to content

Commit fe6cefc

Browse files
committed
Downgrade To A Warning
1 parent 0a9a5c6 commit fe6cefc

File tree

3 files changed

+33
-4
lines changed

3 files changed

+33
-4
lines changed

lib/Sema/TypeCheckPattern.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1294,8 +1294,11 @@ Pattern *TypeChecker::coercePatternToType(ContextualPattern pattern,
12941294
} else {
12951295
// ...but for non-optional types it can never match! Diagnose it.
12961296
diags.diagnose(NLE->getLoc(),
1297-
diag::value_type_comparison_with_nil_illegal, type);
1298-
return nullptr;
1297+
diag::value_type_comparison_with_nil_illegal, type)
1298+
.warnUntilSwiftVersion(6);
1299+
1300+
if (type->getASTContext().isSwiftVersionAtLeast(6))
1301+
return nullptr;
12991302
}
13001303
}
13011304

test/Constraints/result_builder_diags.swift

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -826,3 +826,30 @@ func test_redeclations() {
826826
let (foo, foo) = (5, 6) // expected-error {{invalid redeclaration of 'foo'}} expected-note {{'foo' previously declared here}}
827827
}
828828
}
829+
830+
func test_rdar89742267() {
831+
@resultBuilder
832+
struct Builder {
833+
static func buildBlock<T>(_ t: T) -> T { t }
834+
static func buildEither<T>(first: T) -> T { first }
835+
static func buildEither<T>(second: T) -> T { second }
836+
}
837+
838+
struct S {}
839+
840+
enum Hey {
841+
case listen
842+
}
843+
844+
struct MyView {
845+
var entry: Hey
846+
847+
@Builder var body: S {
848+
switch entry {
849+
case .listen: S()
850+
case nil: S() // expected-warning {{type 'Hey' is not optional, value can never be nil; this is an error in Swift 6}}
851+
default: S()
852+
}
853+
}
854+
}
855+
}

test/stmt/switch_nil.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ enum Hey {
66

77
func test() {
88
switch Hey.listen {
9-
case nil: // expected-error{{type 'Hey' is not optional, value can never be nil}}
9+
case nil: // expected-warning {{type 'Hey' is not optional, value can never be nil}}
1010
break
1111
default:
1212
break
1313
}
1414
}
15-

0 commit comments

Comments
 (0)