Skip to content

Commit 10f680b

Browse files
committed
Add missing r-value coercion in type(of:)
When this was migrated over to the awesome new special representation of type(of:) the argument coercion didn’t come with it. The missing load expression caused any l-value run through type(of:) to crash in the verifier.
1 parent f1231a4 commit 10f680b

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

lib/Sema/CSApply.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6321,6 +6321,7 @@ Expr *ExprRewriter::finishApply(ApplyExpr *apply, Type openedType,
63216321
auto arg = apply->getArg();
63226322
if (auto tuple = dyn_cast<TupleExpr>(arg))
63236323
arg = tuple->getElements()[0];
6324+
arg = cs.coerceToRValue(arg);
63246325
auto replacement = new (tc.Context)
63256326
DynamicTypeExpr(apply->getFn()->getLoc(),
63266327
apply->getArg()->getStartLoc(),
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// RUN: %target-typecheck-verify-swift -swift-version 4
2+
3+
// Make sure an r-value coercion is performed on the argument in Swift 4 mode.
4+
var x: Int = 1
5+
_ = type(of: x)
6+

0 commit comments

Comments
 (0)