nim-works/nimskull

fields iterators causes incorrect lineinfo placement on `cannot evaluate at compile time` errors

Open

#1,617 opened on Sep 16, 2025

 (3 comments) (0 reactions) (0 assignees)Nim (39 forks)auto 404
bugcompiler/semgood first issue

Repository metrics

Stars
 (346 stars)
PR merge metrics
 (PR metrics pending)

Description

The error reported for when a variable is being accessed at compile-time in a fields iterator, uses the line info of the loop rather than the erroneous statement.

Example

type
  Test = object
    a: int

var test = Test(a: 1)

for v in test.fields:
  when v == 2: discard

Actual Output

/home/chronos/test/main.nim(7, 10) Error: cannot evaluate at compile time: test

Expected Output

/home/chronos/test/main.nim(8, 7) Error: cannot evaluate at compile time: test

Possible Solution

Additional Information

Seems to be an issue of the lineinfo not being set correctly, since the information is attached to the for loop rather than the statement.

References

Contributor guide