PLC-lang/rusty

Evaluate all array elements before returning an overflow error

開放

#872 建立於 2023年6月12日

 (0 則留言) (0 個反應) (0 位負責人)Rust (71 個分叉)auto 404
good first issuelow-priority

倉庫指標

星標
 (351 顆星)
PR 合併指標
 (PR 指標待抓取)

描述

Overflow checks for arrays currently stop evaluating after the first element that overflows, e.g.

FUNCTION main : DINT
  VAR
    arr : ARRAY[0..4] OF UDINT := [-1, -2, -3, 4, -5];
  END_VAR
END_FUNCTION

will return

error: This will overflow for type UDINT
  ┌─ target/demo.st:3:36
  │
3 │     arr : ARRAY[0..4] OF UDINT := [-1, -2, -3, 4, -5];
  │                                    ^^ This will overflow for type UDINT

Instead of only reporting -1 here, one would expect to also receive an error message for -2, -3 and -5. Fixing this will require some tweaks in the evalute_with_target_hint function, more specifically this line https://github.com/PLC-lang/rusty/blob/c33bc5f04dcf9294f31920c961eb5050362f15a8/src/resolver/const_evaluator.rs#L341

貢獻者指南