Skip to content

Handle stray LoadExprs in RawRepresentable fix-its #17804

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
Jul 9, 2018
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
8 changes: 7 additions & 1 deletion lib/Sema/CSDiag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4608,8 +4608,14 @@ static bool diagnoseRawRepresentableMismatch(CalleeCandidateInfo &CCI,
return false;

const Expr *expr = argExpr;
if (auto *tupleArgs = dyn_cast<TupleExpr>(argExpr))
if (auto *tupleArgs = dyn_cast<TupleExpr>(argExpr)) {
expr = tupleArgs->getElement(bestMatchIndex);
} else if (auto *misplacedLoad = dyn_cast<LoadExpr>(argExpr)) {
// If there are multiple possible overloads for a single-argument call
// expression, the partially-typed-checked AST may have a load around the
// call parentheses instead of inside them.
expr = misplacedLoad->getSubExpr();
}
expr = expr->getValueProvidingExpr();

auto parameters = bestMatchCandidate->getParameters();
Expand Down
13 changes: 13 additions & 0 deletions test/Sema/enum_raw_representable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,19 @@ func sr8150(bar: Bar) {
// expected-error@-1 {{cannot convert value of type 'Double' to expected argument type 'Bar'}} {{18-18=Bar(rawValue: }} {{21-21=)}}
}

class SR8150Box {
var bar: Bar
init(bar: Bar) { self.bar = bar }
}
// Bonus problem with mutable values being passed.
func sr8150_mutable(obj: SR8150Box) {
sr8150_helper1(obj.bar)
// expected-error@-1 {{cannot convert value of type 'Bar' to expected argument type 'Double'}} {{18-18=}} {{25-25=.rawValue}}

var bar = obj.bar
sr8150_helper1(bar)
// expected-error@-1 {{cannot convert value of type 'Bar' to expected argument type 'Double'}} {{18-18=}} {{21-21=.rawValue}}
}

struct NotEquatable { }

Expand Down