diff options
| author | Yong He <yonghe@outlook.com> | 2022-08-12 07:57:41 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-08-12 07:57:41 -0700 |
| commit | 786f48d32340c36a06865a333ff9066033b5b2bc (patch) | |
| tree | a3f5823e66b59517c6cd4a7d5ddd1774bf10ccb3 /source/slang/slang-check-expr.cpp | |
| parent | b5d84f60d36b81c7e8263048dda031a9be14a106 (diff) | |
Fix logic of `is` operator. (#2359)
Diffstat (limited to 'source/slang/slang-check-expr.cpp')
| -rw-r--r-- | source/slang/slang-check-expr.cpp | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/source/slang/slang-check-expr.cpp b/source/slang/slang-check-expr.cpp index cb75e3078..2ac02b978 100644 --- a/source/slang/slang-check-expr.cpp +++ b/source/slang/slang-check-expr.cpp @@ -1771,30 +1771,35 @@ namespace Slang { // Instead of returning a BoolLiteralExpr, we use a field to indicate this scenario, // so that the language server can still see the original syntax tree. - expr->isAlwaysTrue = true; + expr->constantVal = m_astBuilder->create<BoolLiteralExpr>(); + expr->constantVal->type = m_astBuilder->getBoolType(); + expr->constantVal->value = true; + expr->constantVal->loc = expr->loc; return expr; } // Otherwise, we need to ensure the target type is a subtype of value->type. - // For now we can only support the scenario where `expr->value` is an interface type. - if (!isInterfaceType(originalVal->type)) - { - getSink()->diagnose(expr, Diagnostics::isOperatorValueMustBeInterfaceType); - } expr->value = maybeOpenExistential(originalVal); expr->witnessArg = tryGetSubtypeWitness(expr->typeExpr.type, originalVal->type.type); if (expr->witnessArg) { + // For now we can only support the scenario where `expr->value` is an interface type. + if (!isInterfaceType(originalVal->type)) + { + getSink()->diagnose(expr, Diagnostics::isOperatorValueMustBeInterfaceType); + } return expr; } if (!as<ErrorType>(expr->typeExpr.type) && !as<ErrorType>(expr->value->type.type)) { - getSink()->diagnose(expr, Diagnostics::typeNotInTheSameHierarchy, expr->value->type.type, expr->typeExpr.type); + // The type is not in the same hierarchy, so we evaluate to false. + expr->constantVal = m_astBuilder->create<BoolLiteralExpr>(); + expr->constantVal->type = m_astBuilder->getBoolType(); + expr->constantVal->value = false; + expr->constantVal->loc = expr->loc; } - - expr->type = m_astBuilder->getErrorType(); return expr; } |
