@@ -1631,6 +1631,29 @@ namespace {
16311631 // Build a member reference.
16321632 auto memberRef = resolveConcreteDeclRef (member, memberLocator);
16331633
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+
16341657 // If we're referring to a member type, it's just a type
16351658 // reference.
16361659 if (auto *TD = dyn_cast<TypeDecl>(member)) {
@@ -3222,8 +3245,20 @@ namespace {
32223245
32233246 Expr *visitTypeValueExpr (TypeValueExpr *expr) {
32243247 auto toType = simplifyType (cs.getType (expr));
3225- assert (toType->isEqual (expr->getParamDecl ()->getValueType ()));
3248+ ASSERT (toType->isEqual (expr->getParamDecl ()->getValueType ()));
32263249 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+
32273262 return expr;
32283263 }
32293264
0 commit comments