diff --git a/src/torque/implementation-visitor.cc b/src/torque/implementation-visitor.cc index 8b139ade7c..58caa9e1fd 100644 --- a/src/torque/implementation-visitor.cc +++ b/src/torque/implementation-visitor.cc @@ -541,10 +541,6 @@ const Type* ImplementationVisitor::Visit( base::Optional type; if (stmt->type) { type = TypeVisitor::ComputeType(*stmt->type); - if ((*type)->IsConstexpr() && !stmt->const_qualified) { - ReportError( - "cannot declare variable with constexpr type. Use 'const' instead."); - } } base::Optional init_result; if (stmt->initializer) { @@ -553,6 +549,13 @@ const Type* ImplementationVisitor::Visit( if (type) { init_result = GenerateImplicitConvert(*type, *init_result); } + type = init_result->type(); + if ((*type)->IsConstexpr() && !stmt->const_qualified) { + Error("Use 'const' instead of 'let' for variable '", stmt->name->value, + "' of constexpr type '", (*type)->ToString(), "'.") + .Position(stmt->name->pos) + .Throw(); + } init_result = scope.Yield(*init_result); } else { DCHECK(type.has_value()); diff --git a/test/unittests/torque/torque-unittest.cc b/test/unittests/torque/torque-unittest.cc index 8ad277ec92..9a82498ee4 100644 --- a/test/unittests/torque/torque-unittest.cc +++ b/test/unittests/torque/torque-unittest.cc @@ -207,6 +207,12 @@ TEST(Torque, ConditionalFields) { HasSubstr("aligned")); } +TEST(Torque, ConstexprLetBindingDoesNotCrash) { + ExpectFailingCompilation( + R"(macro FooBar() { let foo = 0; check(foo >= 0); })", + HasSubstr("Use 'const' instead of 'let' for variable 'foo'")); +} + } // namespace torque } // namespace internal } // namespace v8