Skip to content

Commit 9c1bb71

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 61e104c commit 9c1bb71

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
@@ -381,14 +381,15 @@ static Expr *buildDynamicMemberLookupIndexExpr(StringRef name, Type ty,
381381
// Build and type check the string literal index value to the specific
382382
// string type expected by the subscript.
383383
Expr *nameExpr = new (ctx) StringLiteralExpr(name, loc, /*implicit*/true);
384+
(void)cs.TC.typeCheckExpression(nameExpr, dc);
385+
cs.cacheExprTypes(nameExpr);
384386

385387
// Build a tuple so that the argument has a label.
386388
Expr *tuple = TupleExpr::create(ctx, loc, nameExpr, ctx.Id_dynamicMember,
387389
loc, loc, /*hasTrailingClosure*/false,
388390
/*implicit*/true);
389-
(void)cs.TC.typeCheckExpression(tuple, dc, TypeLoc::withoutLoc(ty),
390-
CTP_CallArgument);
391-
cs.cacheExprTypes(tuple);
391+
cs.setType(tuple, ty);
392+
tuple->setType(ty);
392393
return tuple;
393394
}
394395

@@ -4419,13 +4420,17 @@ namespace {
44194420
auto loc = origComponent.getLoc();
44204421
auto fieldName =
44214422
foundDecl->choice.getName().getBaseIdentifier().str();
4422-
auto index = buildDynamicMemberLookupIndexExpr(fieldName, indexType,
4423-
loc, dc, cs);
4424-
4423+
4424+
Expr *nameExpr = new (ctx) StringLiteralExpr(fieldName, loc,
4425+
/*implicit*/true);
4426+
(void)cs.TC.typeCheckExpression(nameExpr, dc);
4427+
cs.cacheExprTypes(nameExpr);
4428+
44254429
origComponent = KeyPathExpr::Component::
4426-
forUnresolvedSubscript(ctx, loc, index, {}, loc, loc,
4427-
/*trailingClosure*/nullptr);
4428-
cs.setType(origComponent.getIndexExpr(), index->getType());
4430+
forUnresolvedSubscript(ctx, loc,
4431+
{nameExpr}, {ctx.Id_dynamicMember}, {loc},
4432+
loc, /*trailingClosure*/nullptr);
4433+
cs.setType(origComponent.getIndexExpr(), indexType);
44294434
}
44304435

44314436
auto subscriptType =

0 commit comments

Comments
 (0)