Skip to content

Commit d5e638f

Browse files
authored
Merge pull request #5373 from DougGregor/iuo-infer-28621624
2 parents c582190 + 4b9adae commit d5e638f

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/Sema/CSSolver.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -966,6 +966,7 @@ static PotentialBindings getPotentialBindings(ConstraintSystem &cs,
966966

967967
// Don't deduce IUO types.
968968
Type alternateType;
969+
bool adjustedIUO = false;
969970
if (kind == AllowedBindingKind::Supertypes &&
970971
constraint->getKind() >= ConstraintKind::Conversion &&
971972
constraint->getKind() <= ConstraintKind::OperatorArgumentConversion) {
@@ -974,6 +975,7 @@ static PotentialBindings getPotentialBindings(ConstraintSystem &cs,
974975
cs.lookThroughImplicitlyUnwrappedOptionalType(innerType)) {
975976
type = OptionalType::get(objectType);
976977
alternateType = objectType;
978+
adjustedIUO = true;
977979
}
978980
}
979981

@@ -1000,7 +1002,7 @@ static PotentialBindings getPotentialBindings(ConstraintSystem &cs,
10001002
}
10011003

10021004
if (exactTypes.insert(type->getCanonicalType()).second)
1003-
addPotentialBinding({type, kind, None});
1005+
addPotentialBinding({type, kind, None}, /*allowJoinMeet=*/!adjustedIUO);
10041006
if (alternateType &&
10051007
exactTypes.insert(alternateType->getCanonicalType()).second)
10061008
addPotentialBinding({alternateType, kind, None}, /*allowJoinMeet=*/false);

test/Constraints/optional.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,14 @@ func testTernaryWithNil(b: Bool, s: String, i: Int) {
130130
let t4 = b ? nil : 1
131131
let _: Double = t4 // expected-error{{value of type 'Int?'}}
132132
}
133+
134+
// inference with IUOs
135+
infix operator ++++
136+
137+
protocol PPPP {
138+
static func ++++(x: Self, y: Self) -> Bool
139+
}
140+
141+
func compare<T: PPPP>(v: T, u: T!) -> Bool {
142+
return v ++++ u
143+
}

0 commit comments

Comments
 (0)