nim-works / nimskull

An in development statically typed systems programming language; with sustainability at its core. We, the community of users, maintain it.
https://nim-works.github.io/nimskull/index.html
Other
275 stars 39 forks source link

Crash in transf due to malformed proc passed as argument #1381

Closed DiThi closed 1 month ago

DiThi commented 2 months ago

Example 1:

var x: seq[proc(i: int)]
x.add proc(e: auto) = echo i

Example 2:

proc x(f: proc(i: int)) = discard
x proc(e: auto) = echo i

The first example produces:

nim.nim                  nim
nim.nim                  handleCmdLine
main.nim                 mainCommand
main.nim                 compileToBackend
main.nim                 commandCompileToC
cbackend.nim             generateCode
cbackend.nim             generateCode
backends.nim             preprocess
transf.nim               transformBodyWithCache
transf.nim               transformBody
transf.nim               processTransf
transf.nim               transform nkError 389603 test.nim(2, 23)
idioms.nim               unreachableImpl
assertions.nim           raiseAssert
fatal.nim                sysFatal
Error: unhandled exception: transf.nim(1223, 16) unreachable: errors can't reach here [AssertionDefect]

and the second example does the same except with nkError 389709

zerbina commented 2 months ago

The underlying cause is the same for both examples: semInferredLambda doesn't wrap the lambda expression in a wrapper error when the body has an error, leading to the body ultimately ends up in transf.

DiThi commented 1 month ago

I've found another crash that seems related to this one (but it may be an issue on its own).

proc getf(f: proc(x: int): int) = discard
getf proc(x: auto): auto = foo

It's a different error unless I do something about the second auto, e.g.

proc getf(f: proc(x: int): int) = discard
getf proc(x: auto): int = foo

where it gets the same error as in the first post.

zerbina commented 1 month ago

The underlying cause is the same (i.e., semInferredLambda not handling nkError correctly).