elvis icon indicating copy to clipboard operation
elvis copied to clipboard

Treats an out of bounds access for an object sequence as truthy

Open ajusa opened this issue 2 years ago • 1 comments

Not quite sure what is going on, but I do have a minimal reproducible example:

import elvis

var a: seq[int] = @[]
echo ?(a[0])

type Story* = object
var stories: seq[Story]
echo ?(stories[0])

This prints

false
true

which is pretty counter intuitive, as I'd expect the second echo to print false as well.

ajusa avatar Mar 06 '23 07:03 ajusa

It presently does not work properly but a start of a solution resides: https://github.com/beef331/elvis/commit/776618c14a7d0f89e7d06ee103519295645ec9b6

Basically what one needs to do is to break apart the untyped expression unto a chain of truthy(let arg = expr; arg) and truthy(let arg2 = expr(arg1); arg2) ....) this does that and compiles for some amount of these, but due to untyped AST requirement it needs to be smarter.

beef331 avatar Mar 06 '23 08:03 beef331