Skip to content

Comptime transform: a payload variant call folded to its shorthand no longer matches its pattern at run time #3016

Closed

Description

@ehartford

Found on stack #3008 (layer compiler-admissions). ct_try_fold_type_call speculatively evaluates a Type.method(args) call with a known static receiver; once ct_build_value_tree learned to write a CV_ENUM with payload back as .Variant(payload), this program mismatched:

enum DbError:
    NotFound(str, str)
    Busy
enum AppError:
    Db(DbError)
    Io
fn main:
    let g = AppError.Db(DbError.NotFound("users", "42"))
    match g:
        .Db(.NotFound(a, b)) => print(f"ok {a} {b}")
        _ => print("MISMATCH")

prints MISMATCH when the call is folded, while the same text written as let f: AppError = .Db(.NotFound("users", "42")) matches on every compiler. So the folded tree differs from the parsed shorthand in something the match reads (the enum identity of the nested variant, or the payload layout the binding is given, #1836's type recording). The layer leaves such calls unfolded (ct_try_fold_type_call returns the node when the value is an enum with payload); the fold still serves a comptime block's result (const CIRCLE: Shape = .Circle(7), behav_2950_comptime_payload_variant). Route: --dump-typed of the folded unit against the parsed one, then lldb on ct_build_value_tree.

Activity

  1. added 3 commits that reference this issue on Nov 3, 2026
  2. ehartford commented on Nov 7, 2026

    @ehartford
    ContributorAuthor

    Fixed in #3056 (merged as afbdbb1).

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