diff options
| author | Theresa Foley <10618364+tangent-vector@users.noreply.github.com> | 2025-04-24 14:19:45 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-04-25 00:19:45 +0300 |
| commit | a4dc6247ade19eac03e0643d56f0877d39aaec6e (patch) | |
| tree | 3dbb88077ec38ce3c16ef9ac688f351aea13a958 /examples/reflection-parameter-blocks | |
| parent | 212d2f5978c514332783e3dd0355f207e9f1ba77 (diff) | |
Fix attempt to construct an abstract AST node (#6905)
Work on #6892
The function `tryInferLoopMaxIterations` in `slang-check-stmt.cpp` was
doing:
auto litExpr = m_astBuilder->create<LiteralExpr>();
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->create<IntegerLiteralExpr>();
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.
Diffstat (limited to 'examples/reflection-parameter-blocks')
0 files changed, 0 insertions, 0 deletions
