<feed xmlns='http://www.w3.org/2005/Atom'>
<title>slang.git/tests/bugs/serialization, branch master</title>
<subtitle>Making it easier to work with shaders</subtitle>
<id>https://git.yummers.dev/slang.git/atom?h=master</id>
<link rel='self' href='https://git.yummers.dev/slang.git/atom?h=master'/>
<link rel='alternate' type='text/html' href='https://git.yummers.dev/slang.git/'/>
<updated>2025-04-24T21:19:45+00:00</updated>
<entry>
<title>Fix attempt to construct an abstract AST node (#6905)</title>
<updated>2025-04-24T21:19:45+00:00</updated>
<author>
<name>Theresa Foley</name>
<email>10618364+tangent-vector@users.noreply.github.com</email>
</author>
<published>2025-04-24T21:19:45+00:00</published>
<link rel='alternate' type='text/html' href='https://git.yummers.dev/slang.git/commit/?id=a4dc6247ade19eac03e0643d56f0877d39aaec6e'/>
<id>urn:sha1:a4dc6247ade19eac03e0643d56f0877d39aaec6e</id>
<content type='text'>
Work on #6892

The function `tryInferLoopMaxIterations` in `slang-check-stmt.cpp` was
doing:

    auto litExpr = m_astBuilder-&gt;create&lt;LiteralExpr&gt;();

but the declaration of `LiteralExpr` in `slang-ast-expr.h` had been
marked as abstract, during the switch to using the `slang-fiddle` tool
to generate code:

    FIDDLE(abstract)
    class LiteralExpr : public Expr
    { ... }

In this case, the intention of the AST design is that `LiteralExpr`
should be kept abstract, and only the concrete subclasses should
ever be instantiated.

Because of some historical design choices, the `ASTNodeType`
enumeration includes both the concrete and abstract AST classes, so
the code ended up constructing a `LiteralExpr` that had the tag
`ASTNodeType::LiteralExpr`. Then attempts to use the `ASTNodeDispatcher`
code on such a node caused crashes, because the dispatcher code only
included `case` statements for the non-abstract `ASTNodeType`s.

The quick fix here was to change the `tryInferLoopMaxIterations`
function to instead do:

    auto litExpr = m_astBuilder-&gt;create&lt;IntegerLiteralExpr&gt;();

A test case was added to help catch any future regressions on this
specific issue.

A more long-term fix should involve introducing code that statically
and/or dynamically prohibits the creation of instances of AST node
classes that have been marked abstract.</content>
</entry>
</feed>
