Skip to content

Commit 0434d58

Browse files
authored
Merge pull request #27123 from hborla/missing-conformance-diag
[ConstraintSystem] Allow fixing missing conformance failures for `Void` and uninhabited types.
2 parents 5664045 + b2ec5b9 commit 0434d58

File tree

5 files changed

+14
-14
lines changed

5 files changed

+14
-14
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3901,11 +3901,6 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint(
39013901
return recordFix(fix) ? SolutionKind::Error : SolutionKind::Solved;
39023902
}
39033903

3904-
// Let's not try to fix missing conformance for Void
3905-
// or Never because that doesn't really make sense.
3906-
if (type->isVoid() || type->isUninhabited())
3907-
return SolutionKind::Error;
3908-
39093904
if (path.back().is<LocatorPathElt::AnyRequirement>()) {
39103905
// If this is a requirement associated with `Self` which is bound
39113906
// to `Any`, let's consider this "too incorrect" to continue.

test/Constraints/rdar44770297.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ protocol P {
44
associatedtype A
55
}
66

7-
func foo<T: P>(_: () throws -> T) -> T.A? { // expected-note {{in call to function 'foo'}}
7+
func foo<T: P>(_: () throws -> T) -> T.A? { // expected-note {{where 'T' = 'Never'}}
88
fatalError()
99
}
1010

11-
let _ = foo() {fatalError()} & nil // expected-error {{generic parameter 'T' could not be inferred}}
11+
let _ = foo() {fatalError()} & nil // expected-error {{global function 'foo' requires that 'Never' conform to 'P'}}

test/type/opaque.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,11 @@ func recursion(x: Int) -> some P {
172172
return recursion(x: x - 1)
173173
}
174174

175-
// FIXME: We need to emit a better diagnostic than the failure to convert Never to opaque.
176-
func noReturnStmts() -> some P { fatalError() } // expected-error{{cannot convert return expression of type 'Never' to return type 'some P'}} expected-error{{no return statements}}
175+
func noReturnStmts() -> some P {} // expected-error {{function declares an opaque return type, but has no return statements in its body from which to infer an underlying type}}
176+
177+
func returnUninhabited() -> some P { // expected-note {{opaque return type declared here}}
178+
fatalError() // expected-error{{return type of global function 'returnUninhabited()' requires that 'Never' conform to 'P'}}
179+
}
177180

178181
func mismatchedReturnTypes(_ x: Bool, _ y: Int, _ z: String) -> some P { // expected-error{{do not have matching underlying types}}
179182
if x {

validation-test/Sema/type_checker_crashers_fixed/rdar50869732.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ struct Generic<T> {
1010

1111
@_functionBuilder
1212
struct Builder {
13-
static func buildBlock<C0, C1>(_ c0: C0, _ c1: C1)
13+
static func buildBlock<C0, C1>(_ c0: C0, _ c1: C1) // expected-note {{where 'C0' = 'Empty'}} expected-note {{where 'C1' = 'Test<Empty>'}}
1414
-> Generic<(C0, C1)> where C0 : P, C1 : P {
1515
return Generic((c0, c1))
1616
}
@@ -24,11 +24,13 @@ struct Empty {
2424
init() {}
2525
}
2626

27-
struct Test<T> where T : P {
27+
struct Test<T> where T : P { // expected-note {{where 'T' = 'Empty'}}
2828
init(@Builder _: () -> T) {}
2929
}
3030

3131
let x = G {
32+
// expected-error@-1 {{static method 'buildBlock' requires that 'Empty' conform to 'P'}}
33+
// expected-error@-2 {{static method 'buildBlock' requires that 'Test<Empty>' conform to 'P'}}
3234
Empty()
33-
Test { <#code#> } // expected-error {{editor placeholder in source file}}
35+
Test { Empty() } // expected-error {{generic struct 'Test' requires that 'Empty' conform to 'P'}}
3436
}

validation-test/compiler_crashers_2_fixed/0196-rdar48937223.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
protocol P {}
44

5-
func fn<T, U: P>(_ arg1: T, arg2: (T) -> U) {}
5+
func fn<T, U: P>(_ arg1: T, arg2: (T) -> U) {} // expected-note {{where 'U' = '()'}}
66

77
func test(str: String) {
8-
fn(str) { arg in
8+
fn(str) { arg in // expected-error {{global function 'fn(_:arg2:)' requires that '()' conform to 'P'}}
99
<#FOO#> // expected-error {{editor placeholder in source file}}
1010
}
1111
}

0 commit comments

Comments
 (0)