Skip to content

Undefined Behavior when using const/let tables (Nim v0.18.1) #7332

@Drakoriss

Description

@Drakoriss

In new version of Nim I've got different results when trying to receive values from table:

import tables
const tableOfArray = {
    "one": [true, false, false],
    "two": [false, true, false],
    "three": [false, false, true]
}.toTable()
for i in 0..2:
    echo tableOfArray["two"][i]

Code above must print false true false to console, but instead it can return all values as false. Or fall into infinity loop. Or throw exception. Anything but proper result.
Same if I change const to let. But it works when I use var:

var tableOfArray = {
    "one": [true, false, false],
    "two": [false, true, false],
    "three": [false, false, true]
}.toTable()

When I use sequence instead of array it works too:

const tableOfArray = {
    "one": @[true, false, false],
    "two": @[false, true, false],
    "three": @[false, false, true]
}.toTable()

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions