Skip to content

Commit b9367d1

Browse files
committed
[ConstraintSystem] Allow fixing missing conformance failures for
`Void` and uninhabited types.
1 parent d1f139c commit b9367d1

File tree

3 files changed

+5
-9
lines changed

3 files changed

+5
-9
lines changed

lib/Sema/CSSimplify.cpp

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

3974-
// Let's not try to fix missing conformance for Void
3975-
// or Never because that doesn't really make sense.
3976-
if (type->isVoid() || type->isUninhabited())
3977-
return SolutionKind::Error;
3978-
39793974
if (path.back().is<LocatorPathElt::AnyRequirement>()) {
39803975
// If this is a requirement associated with `Self` which is bound
39813976
// 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: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,9 @@ 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-note {{opaque return type declared here}}
176+
fatalError() // expected-error{{return type of global function 'noReturnStmts()' requires that 'Never' conform to 'P'}}
177+
}
177178

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

0 commit comments

Comments
 (0)