Skip to content

Commit

Permalink
Fix param == ? comparison for type-constrained param
Browse files Browse the repository at this point in the history
Signed-off-by: Anna Rift <[email protected]>
  • Loading branch information
riftEmber committed Nov 22, 2024
1 parent c9fc6f9 commit 0d61e74
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions frontend/lib/resolution/resolution-queries.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3790,21 +3790,9 @@ static bool resolveFnCallSpecial(Context* context,
}

if ((ci.name() == USTR("==") || ci.name() == USTR("!="))) {
if (ci.numActuals() == 2 || ci.hasQuestionArg()) {
if (ci.numActuals() == 2) {
auto lhs = ci.actual(0).type();

QualifiedType rhs;
if (ci.hasQuestionArg()) {
// support type and param comparisions with '?'
if (lhs.isType()) {
rhs = QualifiedType(QualifiedType::TYPE, AnyType::get(context));
} else if (lhs.isParam()) {
rhs = QualifiedType(QualifiedType::PARAM, AnyType::get(context),
nullptr);
}
} else {
rhs = ci.actual(1).type();
}
auto rhs = ci.actual(1).type();

bool bothType = lhs.kind() == QualifiedType::TYPE &&
rhs.kind() == QualifiedType::TYPE;
Expand All @@ -3817,6 +3805,19 @@ static bool resolveFnCallSpecial(Context* context,
BoolParam::get(context, result));
return true;
}
} else if (ci.numActuals() == 1 && ci.hasQuestionArg()) {
// support type and param comparisons with '?'
// TODO: will likely need adjustment once we are able to compare a
auto arg = ci.actual(0).type();
if (arg.isType()) {
exprTypeOut =
QualifiedType(QualifiedType::PARAM, BoolType::get(context),
BoolParam::get(context, arg.type()->isAnyType()));
} else if (arg.isParam()) {
exprTypeOut =
QualifiedType(QualifiedType::PARAM, BoolType::get(context),
BoolParam::get(context, arg.param() == nullptr));
}
}
}

Expand Down

0 comments on commit 0d61e74

Please sign in to comment.