nim-works/nimskull

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

開放

#1,617 建立於 2025年9月16日

 (3 則留言) (0 個反應) (0 位負責人)Nim (39 個分叉)auto 404
bugcompiler/semgood first issue

倉庫指標

星標
 (346 顆星)
PR 合併指標
 (30 天內沒有已合併 PR)

描述

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

貢獻者指南