@@ -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)) {
@@ -3223,8 +3246,20 @@ namespace {
32233246
32243247 Expr *visitTypeValueExpr (TypeValueExpr *expr) {
32253248 auto toType = simplifyType (cs.getType (expr));
3226- assert (toType->isEqual (expr->getParamDecl ()->getValueType ()));
3249+ ASSERT (toType->isEqual (expr->getParamDecl ()->getValueType ()));
32273250 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+
32283263 return expr;
32293264 }
32303265
0 commit comments