diff --git a/spicy/toolchain/src/compiler/codegen/parsers/literals.cc b/spicy/toolchain/src/compiler/codegen/parsers/literals.cc index 65d8708bb3..86c98706ef 100644 --- a/spicy/toolchain/src/compiler/codegen/parsers/literals.cc +++ b/spicy/toolchain/src/compiler/codegen/parsers/literals.cc @@ -138,6 +138,8 @@ struct Visitor : public visitor::PreOrder { hilti::util::cannotBeReached(); } + void operator()(hilti::ctor::Coerced* n) final { dispatch(n->coercedCtor()); } + void operator()(hilti::ctor::RegExp* n) final { auto re = hilti::ID(fmt("__re_%" PRId64, lp->production->tokenID())); @@ -249,7 +251,7 @@ struct Visitor : public visitor::PreOrder { hilti::util::cannotBeReached(); } - void operator()(hilti::expression::Ctor* n) final { result = lp->buildParser(n->ctor()); } + void operator()(hilti::expression::Ctor* n) final { dispatch(n->ctor()); } Expression* parseInteger(UnqualifiedType* type, Expression* expected, const Meta& meta) { auto offset = [this](Expression* view) { return builder()->memberCall(view, "offset"); }; @@ -419,7 +421,8 @@ Expression* ParserBuilder::parseLiteral(const Production& p, Expression* dst) { if ( auto e = LiteralParser(this, &p, dst).buildParser(p.expression()) ) return e; - hilti::logger().internalError(fmt("codegen: literal parser did not return expression for '%s'", *p.expression())); + hilti::logger().internalError(fmt("codegen: literal parser did not return expression for '%s' (%s)", + *p.expression(), p.expression()->typename_())); } void ParserBuilder::skipLiteral(const Production& p) { diff --git a/tests/spicy/types/integer/parse-coerced-ctor.spicy b/tests/spicy/types/integer/parse-coerced-ctor.spicy new file mode 100644 index 0000000000..37a14cbfb8 --- /dev/null +++ b/tests/spicy/types/integer/parse-coerced-ctor.spicy @@ -0,0 +1,11 @@ +# @TEST-EXEC: printf a | spicy-driver -d %INPUT >output +# +# @TEST-DOC: Checks that the literals parsers follows coercions; regression test for #1858 + +module foo; + +const a: uint8 = 97; # will be coerced + +public type X = unit { + : a; +};