Merge pull request #78248 from Azoy/value-generic-static-member

[NameLookup] Allow value generics to show up as static members
This commit is contained in:
Alejandro Alonso
2025-04-16 08:03:46 -07:00
parent b684e716fe
commit 12919a2300
16 changed files with 256 additions and 38 deletions

View File

@@ -1454,23 +1454,25 @@ public:
};
class TypeValueExpr : public Expr {
GenericTypeParamDecl *paramDecl;
DeclNameLoc loc;
TypeRepr *repr;
Type paramType;
/// Create a \c TypeValueExpr from a given generic value param decl.
TypeValueExpr(DeclNameLoc loc, GenericTypeParamDecl *paramDecl) :
Expr(ExprKind::TypeValue, /*implicit*/ false), paramDecl(paramDecl),
loc(loc), paramType(nullptr) {}
/// Create a \c TypeValueExpr from a given type representation.
TypeValueExpr(TypeRepr *repr) :
Expr(ExprKind::TypeValue, /*implicit*/ false), repr(repr),
paramType(nullptr) {}
public:
/// Create a \c TypeValueExpr for a given \c GenericTypeParamDecl.
/// Create a \c TypeValueExpr for a given \c TypeDecl.
///
/// The given location must be valid.
static TypeValueExpr *createForDecl(DeclNameLoc Loc, GenericTypeParamDecl *D);
static TypeValueExpr *createForDecl(DeclNameLoc loc, TypeDecl *d,
DeclContext *dc);
GenericTypeParamDecl *getParamDecl() const {
return paramDecl;
GenericTypeParamDecl *getParamDecl() const;
TypeRepr *getRepr() const {
return repr;
}
/// Retrieves the corresponding parameter type of the value referenced by this
@@ -1485,9 +1487,7 @@ public:
this->paramType = paramType;
}
SourceRange getSourceRange() const {
return loc.getSourceRange();
}
SourceRange getSourceRange() const;
static bool classof(const Expr *E) {
return E->getKind() == ExprKind::TypeValue;

View File

@@ -257,6 +257,7 @@ LANGUAGE_FEATURE(SendableCompletionHandlers, 463, "Objective-C completion handle
LANGUAGE_FEATURE(IsolatedConformances, 470, "Global-actor isolated conformances")
LANGUAGE_FEATURE(AsyncExecutionBehaviorAttributes, 0, "@concurrent and nonisolated(nonsending)")
LANGUAGE_FEATURE(GeneralizedIsSameMetaTypeBuiltin, 465, "Builtin.is_same_metatype with support for noncopyable/nonescapable types")
LANGUAGE_FEATURE(ValueGenericsNameLookup, 452, "Value generics appearing as static members for namelookup")
// Swift 6
UPCOMING_FEATURE(ConciseMagicFile, 274, 6)