Skip to content

Commit

Permalink
insert the implements stmt at the correct scope
Browse files Browse the repository at this point in the history
Signed-off-by: Jade Abraham <[email protected]>
  • Loading branch information
jabraham17 committed Sep 9, 2024
1 parent 5578c06 commit 874fb5b
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion compiler/AST/AggregateType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2900,6 +2900,21 @@ void AggregateType::addClassToHierarchy() {
addClassToHierarchy(localSeen);
}

static BlockStmt* getEnclosingBlockForImplements(Symbol* sym) {
auto parentSym = sym->defPoint->parentSymbol;
if (auto fn = toFnSymbol(parentSym)) {
return fn->body;
} else if (auto mod = toModuleSymbol(parentSym)) {
return mod->block;
} else if( auto ty = toTypeSymbol(parentSym)) {
return getEnclosingBlockForImplements(ty);
} else {
// Fallback, this shouldn't happen but if it does, we'll just return the
// module's block
return sym->getModule()->block;
}
}

void AggregateType::addClassToHierarchy(std::set<AggregateType*>& localSeen) {
// classes already in hierarchy
static std::set<AggregateType*> globalSeen;
Expand Down Expand Up @@ -2941,7 +2956,7 @@ void AggregateType::addClassToHierarchy(std::set<AggregateType*>& localSeen) {

auto ifcActuals = new CallExpr(PRIM_ACTUALS_LIST, new SymExpr(implementFor));
auto istmt = ImplementsStmt::build(isym->name, ifcActuals, nullptr);
this->symbol->getModule()->block->insertAtTail(istmt);
getEnclosingBlockForImplements(this->symbol)->insertAtTail(istmt);

expr->remove();
continue;
Expand Down

0 comments on commit 874fb5b

Please sign in to comment.