-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Open
timotheecour/Nim
#795Labels
const`const x=expr` or `static: stmt``const x=expr` or `static: stmt`
Description
opcLdDeref gives wrong results in VM inside static block
Example 1
when true: # D20200405T172240
# proc fun() = # would work
template fun() = # fails
var s = @[10,11,12]
let z = s[0].addr
doAssert z[] == 10
z[] = 100
doAssert z[] == 100
doAssert s[0] == 100 # fails here
static: fun() # fails
fun() # would workCurrent Output
doAssert s[0] == 100 fails
Expected Output
works
Example 2
shows that pointer is conflated for value:
template fun() =
var s = @[10,11,12]
echo cast[int](s[0].addr) # 4323682360
let z = s[0].addr
echo cast[int](z) # 10 => BUG
static: fun() # failsExample 3
when true: # D20200405T172849:here
template fun() =
# proc fun() = # would work
var s = @[10.1,11.2,12.3]
echo cast[int](s[0].addr)
let z = s[0].addr
echo cast[int](z)
static: fun() # failsError: unhandled exception: 'intVal' is not accessible using discriminant 'kind' of type 'TNode' [FieldError]
Possible Solution
- a fix similar to fix SIGSEGV in VM in opcLdDeref #13865 could help
- maybe it's time to introduce
nkPtrLit(right now it's an alias ofnkIntLit) unless we can fix this cleanly withnfIsPtr+ tyPtrchecks - EDIT: as many other issues, this would be fixed by transform
static: stmtandconst foo = exprinto immediately invoked lambas => fixes many bugs RFCs#276
Additional Information
- devel f1fd3ef
- never worked
Metadata
Metadata
Assignees
Labels
const`const x=expr` or `static: stmt``const x=expr` or `static: stmt`