Commit d04ab197 authored by Tobias Tebbi's avatar Tobias Tebbi Committed by Commit Bot

[torque] allow conditionals with enum constants

Bug: v8:7793, v8:10475
Change-Id: I3c528d07e8d3192d7110ebc81e9e89f79a7c735d
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2196132Reviewed-by: 's avatarNico Hartmann <nicohartmann@chromium.org>
Commit-Queue: Tobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#67764}
parent 91cbf3e3
...@@ -275,6 +275,7 @@ class AbstractType final : public Type { ...@@ -275,6 +275,7 @@ class AbstractType final : public Type {
const Type* NonConstexprVersion() const override { const Type* NonConstexprVersion() const override {
if (non_constexpr_version_) return non_constexpr_version_; if (non_constexpr_version_) return non_constexpr_version_;
if (!IsConstexpr()) return this; if (!IsConstexpr()) return this;
if (parent()) return parent()->NonConstexprVersion();
return nullptr; return nullptr;
} }
...@@ -431,6 +432,13 @@ class V8_EXPORT_PRIVATE UnionType final : public Type { ...@@ -431,6 +432,13 @@ class V8_EXPORT_PRIVATE UnionType final : public Type {
return false; return false;
} }
bool IsConstexpr() const override { return parent()->IsConstexpr(); }
const Type* NonConstexprVersion() const override {
if (!IsConstexpr()) return this;
return parent()->NonConstexprVersion();
}
void Extend(const Type* t) { void Extend(const Type* t) {
if (const UnionType* union_type = UnionType::DynamicCast(t)) { if (const UnionType* union_type = UnionType::DynamicCast(t)) {
for (const Type* member : union_type->types_) { for (const Type* member : union_type->types_) {
......
...@@ -643,6 +643,20 @@ TEST(Torque, EnumInTypeswitch) { ...@@ -643,6 +643,20 @@ TEST(Torque, EnumInTypeswitch) {
} }
} }
)"); )");
ExpectSuccessfulCompilation(R"(
extern enum MyEnum extends Smi {
kA,
kB,
kC,
...
}
@export
macro Test(implicit context: Context)(b: bool): Smi {
return b ? MyEnum::kB : MyEnum::kA;
}
)");
} }
TEST(Torque, ConstClassFields) { TEST(Torque, ConstClassFields) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment