Skip to content

comptime: first()/last()/rest() on fixed arrays and slices are not comptime-evaluable #2386

Closed

Description

@ehartford

After D117's slice/array forms (Sema-declared, MirLower-expanded), comptime use fails loudly:

const A: [i32; 3] = [1, 2, 3]
const F: i32 = comptime A.first() ?? &-1

error: method 'first' is not comptime-evaluable yet. List's first() works in comptime (its std body evaluates); the array/slice forms are compiler-declared with no body for ComptimeEval to run. Add ComptimeEval cases for first/last/rest over comptime array/slice values (place forms yield the element value the same way indexing does; rest() builds the sub-array/sub-slice comptime value), with a comptime fixture next to behav_d117_array_slice_forms.

Activity

  1. ehartford commented on Oct 25, 2026

    @ehartford
    ContributorAuthor

    Triage 2026-10-25, with v0.15.3.0 (main a261b65): reproduced.

    $ cat main.w
    const A: [i32; 3] = [1, 2, 3]
    const F: i32 = comptime A.first() ?? &-1
    fn main: print(F)
    $ with run main.w
    error: method 'first' is not comptime-evaluable yet
     --> main.w:2:25
    

    pre-release: a valid program is refused, and the fix is three evaluator cases beside the List ones.

  2. ehartford commented on Oct 25, 2026

    @ehartford
    ContributorAuthor

    Fixed on main by 2396bc9 (PR #2652, stack #2658; battery green on the stack top 48c1c72). The commit message names the root-cause line and the regression test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions