Skip to content

[Constraint Solver] Don't perform a join when we've adjusted an IUO to an optional #5373

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/Sema/CSSolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -966,6 +966,7 @@ static PotentialBindings getPotentialBindings(ConstraintSystem &cs,

// Don't deduce IUO types.
Type alternateType;
bool adjustedIUO = false;
if (kind == AllowedBindingKind::Supertypes &&
constraint->getKind() >= ConstraintKind::Conversion &&
constraint->getKind() <= ConstraintKind::OperatorArgumentConversion) {
Expand All @@ -974,6 +975,7 @@ static PotentialBindings getPotentialBindings(ConstraintSystem &cs,
cs.lookThroughImplicitlyUnwrappedOptionalType(innerType)) {
type = OptionalType::get(objectType);
alternateType = objectType;
adjustedIUO = true;
}
}

Expand All @@ -1000,7 +1002,7 @@ static PotentialBindings getPotentialBindings(ConstraintSystem &cs,
}

if (exactTypes.insert(type->getCanonicalType()).second)
addPotentialBinding({type, kind, None});
addPotentialBinding({type, kind, None}, /*allowJoinMeet=*/!adjustedIUO);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is equivalent to !alternateType. Either works for me (with the current code having perhaps slightly more clarity given the naming), but I thought I would mention it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I felt like I wanted this to be super-IUO-specific. This goes away when we take IUOs out of the type system.

if (alternateType &&
exactTypes.insert(alternateType->getCanonicalType()).second)
addPotentialBinding({alternateType, kind, None}, /*allowJoinMeet=*/false);
Expand Down
11 changes: 11 additions & 0 deletions test/Constraints/optional.swift
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,14 @@ func testTernaryWithNil(b: Bool, s: String, i: Int) {
let t4 = b ? nil : 1
let _: Double = t4 // expected-error{{value of type 'Int?'}}
}

// inference with IUOs
infix operator ++++

protocol PPPP {
static func ++++(x: Self, y: Self) -> Bool
}

func compare<T: PPPP>(v: T, u: T!) -> Bool {
return v ++++ u
}