Comments (14)
!nim c
iterator it(): bool = discard
for (_) in it(): discard
from nim.
As I've mentioned in the issue, it doesn't matter if the returned type is a tuple or not
My bad, didn't see.
There is a separate bug simplified from that example on 2.0 independent from tuple unpacking (probably same as #21476, same error, same workaround):
proc main =
let x = false
iterator it(): bool =
discard x
for a in it():
discard
main()
which is obtained by removing the parentheses from that example, so the problem does still seem to be with the parentheses.
from nim.
🐧 Linux bisect by @juancarlospaco (collaborator)
devel 👎 FAIL
Output
Error: Command failed: nim c --run -d:nimDebug -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
SIGSEGV: Illegal storage access. (Attempt to read from nil?)
IR
Compiled filesize0 bytes (0 bytes)
Stats
- Started
2024-01-07T23:04:15
- Finished
2024-01-07T23:04:15
- Duration
AST
nnkStmtList.newTree(
nnkIteratorDef.newTree(
newIdentNode("it"),
newEmptyNode(),
newEmptyNode(),
nnkFormalParams.newTree(
newIdentNode("bool")
),
newEmptyNode(),
newEmptyNode(),
nnkStmtList.newTree(
nnkDiscardStmt.newTree(
newEmptyNode()
)
)
),
nnkForStmt.newTree(
nnkVarTuple.newTree(
newIdentNode("_"),
newEmptyNode()
),
nnkCall.newTree(
newIdentNode("it")
),
nnkStmtList.newTree(
nnkDiscardStmt.newTree(
newEmptyNode()
)
)
)
)
stable 👎 FAIL
Output
Error: Command failed: nim c --run -d:nimDebug -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
SIGSEGV: Illegal storage access. (Attempt to read from nil?)
IR
Compiled filesize0 bytes (0 bytes)
Stats
- Started
2024-01-07T23:04:16
- Finished
2024-01-07T23:04:17
- Duration
AST
nnkStmtList.newTree(
nnkIteratorDef.newTree(
newIdentNode("it"),
newEmptyNode(),
newEmptyNode(),
nnkFormalParams.newTree(
newIdentNode("bool")
),
newEmptyNode(),
newEmptyNode(),
nnkStmtList.newTree(
nnkDiscardStmt.newTree(
newEmptyNode()
)
)
),
nnkForStmt.newTree(
nnkVarTuple.newTree(
newIdentNode("_"),
newEmptyNode()
),
nnkCall.newTree(
newIdentNode("it")
),
nnkStmtList.newTree(
nnkDiscardStmt.newTree(
newEmptyNode()
)
)
)
)
2.0.0 👎 FAIL
Output
Error: Command failed: nim c --run -d:nimDebug -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
SIGSEGV: Illegal storage access. (Attempt to read from nil?)
IR
Compiled filesize0 bytes (0 bytes)
Stats
- Started
2024-01-07T23:04:20
- Finished
2024-01-07T23:04:20
- Duration
AST
nnkStmtList.newTree(
nnkIteratorDef.newTree(
newIdentNode("it"),
newEmptyNode(),
newEmptyNode(),
nnkFormalParams.newTree(
newIdentNode("bool")
),
newEmptyNode(),
newEmptyNode(),
nnkStmtList.newTree(
nnkDiscardStmt.newTree(
newEmptyNode()
)
)
),
nnkForStmt.newTree(
nnkVarTuple.newTree(
newIdentNode("_"),
newEmptyNode()
),
nnkCall.newTree(
newIdentNode("it")
),
nnkStmtList.newTree(
nnkDiscardStmt.newTree(
newEmptyNode()
)
)
)
)
1.6.14 👎 FAIL
Output
Error: Command failed: nim c --run -d:nimDebug -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
SIGSEGV: Illegal storage access. (Attempt to read from nil?)
IR
Compiled filesize0 bytes (0 bytes)
Stats
- Started
2024-01-07T23:04:23
- Finished
2024-01-07T23:04:23
- Duration
AST
nnkStmtList.newTree(
nnkIteratorDef.newTree(
newIdentNode("it"),
newEmptyNode(),
newEmptyNode(),
nnkFormalParams.newTree(
newIdentNode("bool")
),
newEmptyNode(),
newEmptyNode(),
nnkStmtList.newTree(
nnkDiscardStmt.newTree(
newEmptyNode()
)
)
),
nnkForStmt.newTree(
nnkVarTuple.newTree(
newIdentNode("_"),
newEmptyNode()
),
nnkCall.newTree(
newIdentNode("it")
),
nnkStmtList.newTree(
nnkDiscardStmt.newTree(
newEmptyNode()
)
)
)
)
1.4.8 👎 FAIL
Output
Error: Command failed: nim c --run -d:nimDebug -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
SIGSEGV: Illegal storage access. (Attempt to read from nil?)
IR
Compiled filesize0 bytes (0 bytes)
Stats
- Started
2024-01-07T23:04:25
- Finished
2024-01-07T23:04:25
- Duration
AST
nnkStmtList.newTree(
nnkIteratorDef.newTree(
newIdentNode("it"),
newEmptyNode(),
newEmptyNode(),
nnkFormalParams.newTree(
newIdentNode("bool")
),
newEmptyNode(),
newEmptyNode(),
nnkStmtList.newTree(
nnkDiscardStmt.newTree(
newEmptyNode()
)
)
),
nnkForStmt.newTree(
nnkVarTuple.newTree(
newIdentNode("_"),
newEmptyNode()
),
nnkCall.newTree(
newIdentNode("it")
),
nnkStmtList.newTree(
nnkDiscardStmt.newTree(
newEmptyNode()
)
)
)
)
1.2.18 👎 FAIL
Output
Error: Command failed: nim c --run -d:nimDebug -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
SIGSEGV: Illegal storage access. (Attempt to read from nil?)
IR
Compiled filesize0 bytes (0 bytes)
Stats
- Started
2024-01-07T23:04:27
- Finished
2024-01-07T23:04:27
- Duration
AST
nnkStmtList.newTree(
nnkIteratorDef.newTree(
newIdentNode("it"),
newEmptyNode(),
newEmptyNode(),
nnkFormalParams.newTree(
newIdentNode("bool")
),
newEmptyNode(),
newEmptyNode(),
nnkStmtList.newTree(
nnkDiscardStmt.newTree(
newEmptyNode()
)
)
),
nnkForStmt.newTree(
nnkVarTuple.newTree(
newIdentNode("_"),
newEmptyNode()
),
nnkCall.newTree(
newIdentNode("it")
),
nnkStmtList.newTree(
nnkDiscardStmt.newTree(
newEmptyNode()
)
)
)
)
1.0.10 👎 FAIL
Output
Error: Command failed: nim c --run -d:nimDebug -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
SIGSEGV: Illegal storage access. (Attempt to read from nil?)
IR
Compiled filesize0 bytes (0 bytes)
Stats
- Started
2024-01-07T23:04:30
- Finished
2024-01-07T23:04:30
- Duration
AST
nnkStmtList.newTree(
nnkIteratorDef.newTree(
newIdentNode("it"),
newEmptyNode(),
newEmptyNode(),
nnkFormalParams.newTree(
newIdentNode("bool")
),
newEmptyNode(),
newEmptyNode(),
nnkStmtList.newTree(
nnkDiscardStmt.newTree(
newEmptyNode()
)
)
),
nnkForStmt.newTree(
nnkVarTuple.newTree(
newIdentNode("_"),
newEmptyNode()
),
nnkCall.newTree(
newIdentNode("it")
),
nnkStmtList.newTree(
nnkDiscardStmt.newTree(
newEmptyNode()
)
)
)
)
Stats
- GCC
11.4.0
- Clang
14.0.0
- NodeJS
19.0
- Created
2024-01-07T23:03:48Z
- Comments
1
- Commands
nim c --run -d:nimDebug -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
🤖 Bug found in 18 minutes
bisecting 7
commits at 0
commits per second
from nim.
Putting parentheses makes it unpack tuples in for loops (old but broken and undocumented behavior, there are other issues open because of this: #19805, #15924). Since (As written below, this is not the cause, but the issue does still seem to be with the parentheses) The for loop tuple unpacking code probably needs cleaning up, it wasn't touched during the recent tuple unpacking refactorsbool
is not a tuple type, the compiler crashes (I surmise). So we need to check that the type is a tuple.
from nim.
Putting parentheses makes it unpack tuples in for loops (old but broken and undocumented behavior, there are other issues open because of this: #19805, #15924). Since
bool
is not a tuple type, the compiler crashes (I surmise). So we need to check that the type is a tuple. The for loop tuple unpacking code probably needs cleaning up, it wasn't touched during the recent tuple unpacking refactors
As I've mentioned in the issue, it doesn't matter if the returned type is a tuple or not, it still crashes. I just minimized the code as much as I possibly could.
proc main() =
let x = false
iterator it(): (bool, bool) =
if x: discard
discard
for (_, _) in it():
discard
main()
On the second thought, to crash with the actual tuple we need to access a captured local variable. So it's might be a separate bug :)
from nim.
I think the first example is invalid code, just as
let (a) = false
gives
Error: tuple expected for tuple unpacking, but got 'int'
from nim.
There is still a bug like #21476 for parentheses but doesn't work with the workaround for #21476. Maybe it is still the same issue though.
proc main() =
let x = false
iterator it(): (bool, bool) {.closure.} = # normally {.closure.} here makes #21476 work
discard x
for (_, _) in it():
discard
main()
Output is segfault.
from nim.
Putting parentheses makes it unpack tuples in for loops (old but broken and undocumented behavior, there are other issues open because of this:
It's quite weird that the tuple unpacking works for nested arrays in the for loop. I didn't know this feature/bug before. It is quite inconsistent with var tuples unpacking.
from nim.
I think the purpose is to prevent an implicit pairs
iterator while allowing items
but we need to make sure this is the only difference and document it
from nim.
I checked #19805. It seems to me that it happened to compile because there is no restriction on the tuple types for tuple unpacking. Though I will wait for #23185 to see whether it breaks something.
errWrongNumberOfVariables
is cute though since it doesn't work for array types (iterAfterVarLent.len
is always 2), it's reasonable to suppose there would have been a check for tuple types.
if n[0].len-1 != iterAfterVarLent.len:
return localErrorNode(c, n, n[0].info, errWrongNumberOfVariables)
I think it's most likely unintentional. The cases in the #19805 failed twice to get itself compiled.
from nim.
I think the example two is the same case as #15924 because there is no var tuple unpacking for closures
from nim.
There is still a bug like #21476 for parentheses but doesn't work with the workaround for #21476. Maybe it is still the same issue though.
proc main() = let x = false iterator it(): (bool, bool) {.closure.} = # normally {.closure.} here makes #21476 work discard x for (_, _) in it(): discard main()Output is segfault.
fixed by #23205
from nim.
fixed by #23205
proc main() =
let x = false
iterator it(): (bool, bool) =
if x: discard
discard
for (_, _) in it(): discard
main()
> Error: internal error: proc has no result symbol
from nim.
That should be the same issue as #21476, as long as it doesn't matter if we use (_, _)
or just _
. Still worth mentioning in #21476 if it is the same issue though since the original example in #21476 is a bit misleading.
from nim.
Related Issues (20)
- Closures capture scope is confusing, leading to unexpective behaviour
- Devel: Illegal storage access in alloc.nim HOT 1
- when nimvm doesn't isolate symbols HOT 3
- when nimvm visible in runtime code causing misexecution due to matching preference rules HOT 2
- [Regression] compiler is not inferring the type of an `enum` marked with the `pure` pragma when there is a type with the same identifier as a value of this enum HOT 7
- SIGSEGV with object variants and RTTI HOT 10
- Bug in C++ codegen for set stringify when setting size HOT 5
- Support `jobserver` when parallelising builds
- On Linux, "nimsuggest" crashes if Nim is installed in /usr/bin and the library in /usr/lib/nim HOT 6
- dom addEventListener has ambiguous types HOT 1
- SigAction isn't missing a field on amd64? HOT 28
- Some C struct can have nested union. This is not supported for now HOT 7
- [Semi-regression] C code contains backtick`gensym HOT 1
- `joinPath` sometimes has extra `.` in the beginning of the path HOT 3
- `hasCustomPragma` does not work on generic types HOT 1
- Rasing an exception leaks memeory in `orc` HOT 1
- Seq IndexDefect leaks memeory in `arc` and `orc`
- https://learnxinyminutes.com/docs/nim/ error in the learning documentation code HOT 3
- `noinit` can cause arc to crash with ref objects HOT 2
- hello world Mummy web server crashes on devel
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nim.