Skip to content

Regression in 2.2.6: SIGBUS with iterator over const Table lookup - premature temporary destruction #25251

@drkameleon

Description

@drkameleon

Nim Version

Nim Compiler Version 2.2.6 [MacOSX: amd64]
Compiled at 2025-10-31
Copyright (c) 2006-2025 by Andreas Rumpf

active boot switches: -d:release

Description

The latest version (2.2.6) crashes when using iterators on temporary values returned from const Table lookups. My guess would be that this is a regression most likely introduced by the optimization to fix #24093.

Minimal example:

import tables, unicode, sequtils

const
    myTable = {
        "en": "abcdefghijklmnopqrstuvwxyz",
    }.toTable

proc buggyVersion(locale: string): seq[Rune] =
    result = toSeq(runes(myTable[locale]))

proc workingVersion(locale: string): seq[Rune] =
    # string lifetime is extended
    let str = myTable[locale]
    result = toSeq(runes(str))

echo "Testing working version..."
let runes2 = workingVersion("en")
echo "Got ", runes2.len, " runes"

echo "Testing buggy version..."
let runes1 = buggyVersion("en")  # <-- CRASHES HERE
echo "Got ", runes1.len, " runes"

Current Output

Testing working version...
Got 26 runes
Testing buggy version...

Expected Output

Testing working version...
Got 26 runes
Testing buggy version...
Got 26 runes

Known Workarounds

No response

Additional Information

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions