@@ -1631,6 +1631,29 @@ namespace {
1631
1631
// Build a member reference.
1632
1632
auto memberRef = resolveConcreteDeclRef(member, memberLocator);
1633
1633
1634
+ // If our member reference is a value generic, then the resulting
1635
+ // expression is the type value one to access the underlying parameter's
1636
+ // value.
1637
+ //
1638
+ // This can occur in code that does something like: 'type(of: x).a' where
1639
+ // 'a' is the static value generic member.
1640
+ if (auto gp = dyn_cast<GenericTypeParamDecl>(member)) {
1641
+ if (gp->isValue()) {
1642
+ auto refType = adjustedOpenedType;
1643
+ auto ref = TypeValueExpr::createForDecl(memberLoc, gp, dc);
1644
+ cs.setType(ref, refType);
1645
+
1646
+ auto gpTy = gp->getDeclaredInterfaceType();
1647
+ auto subs = baseTy->getContextSubstitutionMap();
1648
+ ref->setParamType(gpTy.subst(subs));
1649
+
1650
+ auto result = new (ctx) DotSyntaxBaseIgnoredExpr(base, dotLoc, ref,
1651
+ refType);
1652
+ cs.setType(result, refType);
1653
+ return result;
1654
+ }
1655
+ }
1656
+
1634
1657
// If we're referring to a member type, it's just a type
1635
1658
// reference.
1636
1659
if (auto *TD = dyn_cast<TypeDecl>(member)) {
@@ -3222,8 +3245,20 @@ namespace {
3222
3245
3223
3246
Expr *visitTypeValueExpr(TypeValueExpr *expr) {
3224
3247
auto toType = simplifyType(cs.getType(expr));
3225
- assert (toType->isEqual(expr->getParamDecl()->getValueType()));
3248
+ ASSERT (toType->isEqual(expr->getParamDecl()->getValueType()));
3226
3249
cs.setType(expr, toType);
3250
+
3251
+ auto declRefRepr = cast<DeclRefTypeRepr>(expr->getRepr());
3252
+ auto resolvedTy =
3253
+ TypeResolution::resolveContextualType(declRefRepr, cs.DC,
3254
+ TypeResolverContext::InExpression,
3255
+ nullptr, nullptr, nullptr);
3256
+
3257
+ if (!resolvedTy || resolvedTy->hasError())
3258
+ return nullptr;
3259
+
3260
+ expr->setParamType(resolvedTy);
3261
+
3227
3262
return expr;
3228
3263
}
3229
3264
0 commit comments