New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SIGSEGV: setLen
on a seq doesn't construct objects at CT
#9872
Labels
Comments
insetad of
#[
KEY ICE crash
[SIGSEGV when accessing seq element inside macro (in evalMacroCall) · Issue #9872 · nim-lang/Nim](https://github.com/nim-lang/Nim/issues/9872)
]#
type Foo = object
index: int
when defined(case1):
#[
/Users/timothee/git_clone/nim/timn/config.nims [config.nims used]
/Users/timothee/git_clone/nim/Nim/compiler/nim.nim(109) nim
/Users/timothee/git_clone/nim/Nim/compiler/nim.nim(73) handleCmdLine
/Users/timothee/git_clone/nim/Nim/compiler/cmdlinehelper.nim(91) loadConfigsAndRunMainCommand
/Users/timothee/git_clone/nim/Nim/compiler/main.nim(168) mainCommand
/Users/timothee/git_clone/nim/Nim/compiler/main.nim(78) commandCompileToC
/Users/timothee/git_clone/nim/Nim/compiler/modules.nim(134) compileProject
/Users/timothee/git_clone/nim/Nim/compiler/modules.nim(79) compileModule
/Users/timothee/git_clone/nim/Nim/compiler/passes.nim(194) processModule
/Users/timothee/git_clone/nim/Nim/compiler/passes.nim(86) processTopLevelStmt
/Users/timothee/git_clone/nim/Nim/compiler/sem.nim(603) myProcess
/Users/timothee/git_clone/nim/Nim/compiler/sem.nim(571) semStmtAndGenerateGenerics
/Users/timothee/git_clone/nim/Nim/compiler/semstmts.nim(1987) semStmt
/Users/timothee/git_clone/nim/Nim/compiler/semexprs.nim(915) semExprNoType
/Users/timothee/git_clone/nim/Nim/compiler/semexprs.nim(2548) semExpr
/Users/timothee/git_clone/nim/Nim/compiler/semstmts.nim(1927) semStmtList
/Users/timothee/git_clone/nim/Nim/compiler/semexprs.nim(2436) semExpr
/Users/timothee/git_clone/nim/Nim/compiler/semexprs.nim(897) semDirectOp
/Users/timothee/git_clone/nim/Nim/compiler/semexprs.nim(790) afterCallActions
/Users/timothee/git_clone/nim/Nim/compiler/sem.nim(466) semMacroExpr
/Users/timothee/git_clone/nim/Nim/compiler/vm.nim(1999) evalMacroCall
/Users/timothee/git_clone/nim/Nim/compiler/vm.nim(580) rawExecute
/Users/timothee/git_clone/nim/Nim/lib/system.nim(2969) sysFatal
Error: unhandled exception: index out of bounds [IndexError]
]#
macro fun(): untyped =
let n = 1
var foos: seq[Foo]
foos.setLen n
for i in 0 ..< n:
discard foos[i] # works
echo foos[i].index # Error: unhandled exception: index out of bounds [IndexError]
fun()
when defined(case2):
#[
/Users/timothee/git_clone/nim/timn/config.nims [config.nims used]
/Users/timothee/git_clone/nim/Nim/compiler/nim.nim(109) nim
/Users/timothee/git_clone/nim/Nim/compiler/nim.nim(73) handleCmdLine
/Users/timothee/git_clone/nim/Nim/compiler/cmdlinehelper.nim(91) loadConfigsAndRunMainCommand
/Users/timothee/git_clone/nim/Nim/compiler/main.nim(168) mainCommand
/Users/timothee/git_clone/nim/Nim/compiler/main.nim(78) commandCompileToC
/Users/timothee/git_clone/nim/Nim/compiler/modules.nim(134) compileProject
/Users/timothee/git_clone/nim/Nim/compiler/modules.nim(79) compileModule
/Users/timothee/git_clone/nim/Nim/compiler/passes.nim(194) processModule
/Users/timothee/git_clone/nim/Nim/compiler/passes.nim(86) processTopLevelStmt
/Users/timothee/git_clone/nim/Nim/compiler/sem.nim(603) myProcess
/Users/timothee/git_clone/nim/Nim/compiler/sem.nim(571) semStmtAndGenerateGenerics
/Users/timothee/git_clone/nim/Nim/compiler/semstmts.nim(1987) semStmt
/Users/timothee/git_clone/nim/Nim/compiler/semexprs.nim(915) semExprNoType
/Users/timothee/git_clone/nim/Nim/compiler/semexprs.nim(2548) semExpr
/Users/timothee/git_clone/nim/Nim/compiler/semstmts.nim(1927) semStmtList
/Users/timothee/git_clone/nim/Nim/compiler/semexprs.nim(2472) semExpr
/Users/timothee/git_clone/nim/Nim/compiler/semexprs.nim(2075) semWhen
/Users/timothee/git_clone/nim/Nim/compiler/semexprs.nim(2548) semExpr
/Users/timothee/git_clone/nim/Nim/compiler/semstmts.nim(1927) semStmtList
/Users/timothee/git_clone/nim/Nim/compiler/semexprs.nim(2552) semExpr
/Users/timothee/git_clone/nim/Nim/compiler/semstmts.nim(558) semConst
/Users/timothee/git_clone/nim/Nim/compiler/sem.nim(353) semConstExpr
/Users/timothee/git_clone/nim/Nim/compiler/vm.nim(1908) evalConstExpr
/Users/timothee/git_clone/nim/Nim/compiler/vm.nim(1904) evalConstExprAux
/Users/timothee/git_clone/nim/Nim/compiler/vm.nim(580) rawExecute
/Users/timothee/git_clone/nim/Nim/lib/system.nim(2969) sysFatal
Error: unhandled exception: index out of bounds [IndexError]
]#
proc fun():auto =
let n = 1
var foos: seq[Foo]
foos.setLen n
# var foos = newSeq[Foo](n)
for i in 0 ..< n:
discard foos[i] # works
echo foos[i].index # Error: unhandled exception: index out of bounds [IndexError]
0
const foos = fun()
when defined(case1b):
# this works
macro fun(): untyped =
let n = 1
var foos = newSeq[Foo](n)
for i in 0 ..< n:
discard foos[i] # works
echo foos[i].index # Error: unhandled exception: index out of bounds [IndexError]
fun()
when defined(case2b):
# this works
proc fun():auto =
let n = 1
var foos = newSeq[Foo](n)
for i in 0 ..< n:
discard foos[i] # works
echo foos[i].index # Error: unhandled exception: index out of bounds [IndexError]
0
const foos = fun()
|
timotheecour
changed the title
SIGSEGV when accessing seq element inside macro (in evalMacroCall)
SIGSEGV when accessing seq[ObjectType] element at CT
Dec 6, 2018
timotheecour
changed the title
SIGSEGV when accessing seq[ObjectType] element at CT
SIGSEGV: Dec 6, 2018
setLen
on a seq doesn't construct objects at CT
looks like implementation is wrong:
it's missing object construction I guess?
|
note: this is also wrong for ref's, the ref should be nil
|
timotheecour
added a commit
to timotheecour/Nim
that referenced
this issue
Dec 6, 2018
timotheecour
added a commit
to timotheecour/Nim
that referenced
this issue
Dec 8, 2018
timotheecour
added a commit
that referenced
this issue
Dec 8, 2018
narimiran
pushed a commit
to narimiran/Nim
that referenced
this issue
Dec 15, 2018
(cherry picked from commit f838b1e)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
/cc @Araq
The text was updated successfully, but these errors were encountered: