@@ -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)) {
@@ -3223,8 +3246,20 @@ namespace {
3223
3246
3224
3247
Expr *visitTypeValueExpr (TypeValueExpr *expr) {
3225
3248
auto toType = simplifyType (cs.getType (expr));
3226
- assert (toType->isEqual (expr->getParamDecl ()->getValueType ()));
3249
+ ASSERT (toType->isEqual (expr->getParamDecl ()->getValueType ()));
3227
3250
cs.setType (expr, toType);
3251
+
3252
+ auto declRefRepr = cast<DeclRefTypeRepr>(expr->getRepr ());
3253
+ auto resolvedTy =
3254
+ TypeResolution::resolveContextualType (declRefRepr, cs.DC ,
3255
+ TypeResolverContext::InExpression,
3256
+ nullptr , nullptr , nullptr );
3257
+
3258
+ if (!resolvedTy || resolvedTy->hasError ())
3259
+ return nullptr ;
3260
+
3261
+ expr->setParamType (resolvedTy);
3262
+
3228
3263
return expr;
3229
3264
}
3230
3265
0 commit comments