Skip to content

Commit 122dba3

Browse files
committed
[CSGen] Allow expression pattern types to be holes
(cherry picked from commit 20d7642)
1 parent b321374 commit 122dba3

File tree

4 files changed

+19
-4
lines changed

4 files changed

+19
-4
lines changed

lib/Sema/CSGen.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2920,8 +2920,8 @@ namespace {
29202920
// TODO: we could try harder here, e.g. for enum elements to provide the
29212921
// enum type.
29222922
return setType(
2923-
CS.createTypeVariable(
2924-
CS.getConstraintLocator(locator), TVO_CanBindToNoEscape));
2923+
CS.createTypeVariable(CS.getConstraintLocator(locator),
2924+
TVO_CanBindToNoEscape | TVO_CanBindToHole));
29252925
}
29262926

29272927
llvm_unreachable("Unhandled pattern kind");

test/expr/closure/multi_statement.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,9 +336,10 @@ func test_unknown_refs_in_tilde_operator() {
336336
enum E {
337337
}
338338

339-
let _: (E) -> Void = { // expected-error {{unable to infer closure type in the current context}}
339+
let _: (E) -> Void = {
340340
if case .test(unknown) = $0 {
341341
// expected-error@-1 2 {{cannot find 'unknown' in scope}}
342+
// expected-error@-2 {{type 'E' has no member 'test'}}
342343
}
343344
}
344345
}

validation-test/Sema/type_checker_crashers_fixed/issue-65360.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,17 @@ let _: () -> Void = {
66
for case (is Int)? in [a] {}
77
if case (is Int, is Int) = a {} // expected-error {{cannot convert value of type 'Any?' to specified type '(_, _)'}}
88
}
9+
10+
let _: () -> Void = {
11+
for case (0)? in [a] {}
12+
if case (0, 0) = a {}
13+
// expected-error@-1 {{cannot convert value of type 'Any?' to specified type '(_, _)}}
14+
}
15+
16+
let _: () -> Void = {
17+
for case (0)? in [a] {}
18+
for case (0, 0) in [a] {}
19+
// expected-error@-1 {{conflicting arguments to generic parameter 'Elements' ('[Any]' vs. '[Any?]')}}
20+
// expected-error@-2 {{conflicting arguments to generic parameter 'Element' ('Any' vs. 'Any?')}}
21+
// expected-error@-3 {{conflicting arguments to generic parameter 'Self' ('[Any]' vs. '[Any?]')}}
22+
}

validation-test/Sema/type_checker_crashers_fixed/rdar92327807.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ func test(result: MyEnum, optResult: MyEnum?) {
1010
}
1111

1212
if let .co(42) = result { // expected-error {{pattern matching in a condition requires the 'case' keyword}}
13-
// expected-error@-1 {{type of expression is ambiguous without more context}}
13+
// expected-error@-1 {{type 'MyEnum' has no member 'co'}}
1414
}
1515

1616
if let .co = optResult { // expected-error {{pattern matching in a condition requires the 'case' keyword}}

0 commit comments

Comments
 (0)