Skip to content

Commit 7fb4815

Browse files
authored
Merge pull request #35291 from xedin/sr-13951-followup
[Diagnostics] Attempt `.rawValue` fix only if both types are equally …
2 parents afe9445 + 2641554 commit 7fb4815

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4269,13 +4269,18 @@ bool ConstraintSystem::repairFailures(
42694269
break;
42704270
}
42714271

4272-
if (repairByUsingRawValueOfRawRepresentableType(lhs, rhs))
4273-
break;
4274-
42754272
if (repairViaOptionalUnwrap(*this, lhs, rhs, matchKind, conversionsOrFixes,
42764273
locator))
42774274
break;
42784275

4276+
// Let's wait until both sides are of the same optionality before
4277+
// attempting `.rawValue` fix.
4278+
if (hasConversionOrRestriction(ConversionRestrictionKind::ValueToOptional))
4279+
break;
4280+
4281+
if (repairByUsingRawValueOfRawRepresentableType(lhs, rhs))
4282+
break;
4283+
42794284
// If there are any restrictions here we need to wait and let
42804285
// `simplifyRestrictedConstraintImpl` handle them.
42814286
if (llvm::any_of(conversionsOrFixes,

test/Constraints/sr13951.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,16 @@ func aTransformer(input: Int) -> TheEnum {
2929
func theProblem(input: Int?) {
3030
var enumValue: TheEnum?
3131

32+
func test_arg_position(_: TheEnum?) {}
33+
3234
if let input = input {
3335
enumValue = aTransformer(input: input) // Ok
36+
let _: TheEnum? = enumValue // Ok
37+
let _: TheEnum? = aTransformer(input: input) // Ok
38+
let _: TheEnum?? = enumValue // Ok
39+
let _: TheEnum?? = aTransformer(input: input) // Ok
40+
test_arg_position(aTransformer(input: input)) // Ok
41+
test_arg_position(enumValue) // Ok
3442
}
3543

3644
_ = enumValue // To silence the warning

0 commit comments

Comments
 (0)