I ran into a problem with CallDecl subclassing FuncDecl and would appreciate advice.
call declarations are unnamed (much like subscript and init).
It seems sensible to add new special cases DeclBaseName::Kind::Call and DeclBaseName::createCall(), for call declarations.
However, if that is done, constructing CallDecl triggers an assertion in FuncDecl's constructor and FuncDecl::getName():
FuncDecl(DeclKind Kind,
SourceLoc StaticLoc, StaticSpellingKind StaticSpelling,
SourceLoc FuncLoc,
DeclName Name, SourceLoc NameLoc,
bool Throws, SourceLoc ThrowsLoc,
bool HasImplicitSelfDecl,
GenericParamList *GenericParams, DeclContext *Parent)
: AbstractFunctionDecl(Kind, Parent,
Name, NameLoc,
Throws, ThrowsLoc,
HasImplicitSelfDecl, GenericParams),
StaticLoc(StaticLoc), FuncLoc(FuncLoc) {
assert(!Name.getBaseName().isSpecial());
// ^ Assertion triggered.
// `DeclBaseName::createCall` is special.
}
Identifier getName() const { return getFullName().getBaseIdentifier(); }
// ^ Crashes; `getBaseIdentifier` asserts that base name is not special.
What's the best solution here?
One idea is to use DeclBaseName(Identifier("call")) instead of a special case - but then this makes call declarations conflict with func `call` , which we need to support.
One solution is to make CallDecl inherit from AbstractFunctionDecl (as does ConstructorDecl) instead of FuncDecl - code sharing with FuncDecl is lost, but that seems kind of okay.
Advice would be appreciated!