Skip to content

Commit 387c21f

Browse files
committed
Sema: Don't type check one-element labeled tuples when forming dynamic member lookups
These are going to be banned shortly, so construct them by other means.
1 parent df4b9f4 commit 387c21f

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

lib/Sema/CSApply.cpp

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -403,14 +403,15 @@ static Expr *buildDynamicMemberLookupIndexExpr(StringRef name, Type ty,
403403
// Build and type check the string literal index value to the specific
404404
// string type expected by the subscript.
405405
Expr *nameExpr = new (ctx) StringLiteralExpr(name, loc, /*implicit*/true);
406+
(void)cs.TC.typeCheckExpression(nameExpr, dc);
407+
cs.cacheExprTypes(nameExpr);
406408

407409
// Build a tuple so that the argument has a label.
408410
Expr *tuple = TupleExpr::create(ctx, loc, nameExpr, ctx.Id_dynamicMember,
409411
loc, loc, /*hasTrailingClosure*/false,
410412
/*implicit*/true);
411-
(void)cs.TC.typeCheckExpression(tuple, dc, TypeLoc::withoutLoc(ty),
412-
CTP_CallArgument);
413-
cs.cacheExprTypes(tuple);
413+
cs.setType(tuple, ty);
414+
tuple->setType(ty);
414415
return tuple;
415416
}
416417

@@ -4430,13 +4431,17 @@ namespace {
44304431
auto loc = origComponent.getLoc();
44314432
auto fieldName =
44324433
foundDecl->choice.getName().getBaseIdentifier().str();
4433-
auto index = buildDynamicMemberLookupIndexExpr(fieldName, indexType,
4434-
loc, dc, cs);
4435-
4434+
4435+
Expr *nameExpr = new (ctx) StringLiteralExpr(fieldName, loc,
4436+
/*implicit*/true);
4437+
(void)cs.TC.typeCheckExpression(nameExpr, dc);
4438+
cs.cacheExprTypes(nameExpr);
4439+
44364440
origComponent = KeyPathExpr::Component::
4437-
forUnresolvedSubscript(ctx, loc, index, {}, loc, loc,
4438-
/*trailingClosure*/nullptr);
4439-
cs.setType(origComponent.getIndexExpr(), index->getType());
4441+
forUnresolvedSubscript(ctx, loc,
4442+
{nameExpr}, {ctx.Id_dynamicMember}, {loc},
4443+
loc, /*trailingClosure*/nullptr);
4444+
cs.setType(origComponent.getIndexExpr(), indexType);
44404445
}
44414446

44424447
auto subscriptType =

0 commit comments

Comments
 (0)