Skip to content

fix(sv): evaluate checked tagged members in constant functions #1909

Closed

Description

@tignear

Review follow-up from PR #1883 (head e69a9ed):
#1883 (comment)

P2: constant evaluation rejects all checked tagged-member accesses, including known active members.

Code inspection: ast/const_functions.rs preserves Expr::Call as ConstExpr::Function; typecheck::eval_const_expr_in_env unconditionally returns None for Callee::Checked. The runtime check wrapper therefore prevents a constant function result from being used as an array bound.

Suggested reproducer from the review (not executed in this follow-up):

module Top;
  typedef union tagged packed { void Empty; logic [7:0] Full; } item_t;
  function automatic int size();
    item_t item;
    item = tagged Full 8'd4;
    return item.Full;
  endfunction
  localparam int N = size();
  logic [N-1:0] data;
endmodule

Acceptance criteria:

  • Reproduce the failure through the analyzer and add a portable constant-function regression, including a packed bound of 4.
  • Evaluate the guard before the payload; accept a known true guard and reject inactive or unknown tags. Do not silently bypass the check.
  • Preserve checked result width and signedness; cover negative signed payloads and nested tagged members.
  • Ensure inactive-member constant reads remain rejected and unselected conditional branches are not evaluated eagerly.
  • Run analyzer tests and frontend/backend consumer regressions according to CONTRIBUTING.md.

This remains unimplemented in #1883. Current green CI does not cover this missing behavior.

Activity

  1. added a commit that references this issue on Oct 24, 2026
    3d77a16
  2. tignear commented on Oct 24, 2026

    @tignear
    ContributorAuthor

    Implemented in 3d77a16 on PR #1883. Constant evaluation now checks the active-tag guard before evaluating and resizing the payload. Added coverage for array bounds, signed payloads, nested unions, unselected branches, and inactive/unknown guards.

    Validation: analyzer 802 passed / 3 existing ignored plus doctests; tagged backend regressions 68 passed, with the final adjusted shared case passing all 5 configurations; affected-crate Clippy and formatting passed. Verilator 5.052 and Icarus 13.0 still reject tagged-union syntax; the changed case diagnostics were reviewed and both strict retained-report gates pass.

    New CI and automatic review are pending. This issue will close when #1883 merges.

  3. added a commit that references this issue on Oct 24, 2026
    da00920
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions