Skip to content

Commit

Permalink
Fix some bugs in the way of normal usage of stdlib interfaces
Browse files Browse the repository at this point in the history
Signed-off-by: Danila Fedorin <[email protected]>
  • Loading branch information
DanilaFe committed Dec 13, 2024
1 parent 65a4090 commit 140d6e0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
13 changes: 7 additions & 6 deletions frontend/lib/resolution/resolution-queries.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3022,11 +3022,12 @@ helpCollectVisibileImplementationPoints(Context* context,
}
}

auto visStmts = resolveVisibilityStmts(context, scope);
for (auto visClause : visStmts->visibilityClauses()) {
auto nextScope = visClause.scope();
if (nextScope && asttags::isModule(nextScope->tag())) {
helpCollectVisibileImplementationPoints(context, nextScope, seen, into);
if (auto visStmts = resolveVisibilityStmts(context, scope)) {
for (auto visClause : visStmts->visibilityClauses()) {
auto nextScope = visClause.scope();
if (nextScope && asttags::isModule(nextScope->tag())) {
helpCollectVisibileImplementationPoints(context, nextScope, seen, into);
}
}
}
}
Expand Down Expand Up @@ -5402,7 +5403,7 @@ const ImplementationWitness* findMatchingImplementationPoint(ResolutionContext*
const types::InterfaceType* ift,
const CallScopeInfo& inScopes) {
auto implPoints =
visibileImplementationPointsForInterface(rc->context(), inScopes.lookupScope(), ift->id());
visibileImplementationPointsForInterface(rc->context(), inScopes.lookupScope()->moduleScope(), ift->id());

// TODO: this matches production, in which the first matching generic
// implementation is used if no concrete one is found. It's probably
Expand Down
27 changes: 13 additions & 14 deletions frontend/lib/resolution/return-type-inference.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ processInheritanceExpressionsForAggregateQuery(Context* context,
const PoiScope* poiScope) {
QUERY_BEGIN(processInheritanceExpressionsForAggregateQuery, context, ad, substitutions, poiScope);
const BasicClassType* parentClassType = nullptr;
const AstNode* lastParentClass = nullptr;
const AstNode* parentClassNode = nullptr;
std::vector<ImplementedInterface> implementationPoints;
auto c = ad->toClass();

Expand All @@ -87,24 +87,28 @@ processInheritanceExpressionsForAggregateQuery(Context* context,

auto& rr = r.byAst(inheritExpr);
QualifiedType qt = rr.type();
const BasicClassType* newParentClassType = nullptr;
if (auto t = qt.type()) {
if (auto bct = t->toBasicClassType()) {
parentClassType = bct;
newParentClassType = bct;
} else if (auto ct = t->toClassType()) {
// safe because it's checked for null later.
parentClassType = ct->basicClassType();
newParentClassType = ct->basicClassType();
}
}

bool foundParentClass = qt.isType() && parentClassType != nullptr;
bool foundParentClass = qt.isType() && newParentClassType != nullptr;
if (!c && foundParentClass) {
CHPL_REPORT(context, NonClassInheritance, ad, inheritExpr, parentClassType);
CHPL_REPORT(context, NonClassInheritance, ad, inheritExpr, newParentClassType);
} else if (foundParentClass) {
// It's a valid parent class; is it the only one? (error otherwise).
if (lastParentClass) {
reportInvalidMultipleInheritance(context, c, lastParentClass, inheritExpr);
if (parentClassType) {
CHPL_ASSERT(parentClassNode);
reportInvalidMultipleInheritance(context, c, parentClassNode, inheritExpr);
} else {
parentClassType = newParentClassType;
parentClassNode = inheritExpr;
}
lastParentClass = inheritExpr;

// OK
} else if (qt.isType() && qt.type() && qt.type()->isInterfaceType()) {
Expand All @@ -117,15 +121,10 @@ processInheritanceExpressionsForAggregateQuery(Context* context,
} else {
context->error(inheritExpr, "invalid parent class expression");
parentClassType = BasicClassType::getRootClassType(context);
parentClassNode = inheritExpr;
}
}

// All the parent expressions could've been interfaces, and we just
// inherit from object.
if (!parentClassType) {
parentClassType = BasicClassType::getRootClassType(context);
}

InheritanceExprResolutionResult result {
parentClassType, std::move(implementationPoints)
};
Expand Down

0 comments on commit 140d6e0

Please sign in to comment.