Skip to content

Commit

Permalink
Fix the literals parsers not following coercions.
Browse files Browse the repository at this point in the history
Closes #1858.
  • Loading branch information
rsmmr committed Oct 18, 2024
1 parent 0e3bc48 commit 9cec3fc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
7 changes: 5 additions & 2 deletions spicy/toolchain/src/compiler/codegen/parsers/literals.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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()));

Expand Down Expand Up @@ -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"); };
Expand Down Expand Up @@ -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) {
Expand Down
11 changes: 11 additions & 0 deletions tests/spicy/types/integer/parse-coerced-ctor.spicy
Original file line number Diff line number Diff line change
@@ -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;
};

0 comments on commit 9cec3fc

Please # to comment.