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
280 stars 39 forks source link

compiler crashes when using erroneous generic routine symbol as call argument #1384

Closed zerbina closed 3 months ago

zerbina commented 4 months ago

Example

proc generic[T](x: T) =
  missing # provoke the generic pre-pass to fail (via a symbol lookup error) 

proc f(p: proc(x: int)) =
  discard

f(generic) # <- instantiation is attempted even though the symbol is erroneous

Actual Output

Error: unhandled exception: field 'sons' is not accessible for type 'TNode' using 'kind = nkError' [FieldDefect]

Expected Output

Error: undeclared identifier: 'missing'

Possible Solution

Analyzing the expression goes through semExpr, but not semSym (which would have wrapped the symbol usage in an error), due to the symbol being a skProc.

If the symChoice call part of the nkIdent handling of semExpr results in a single symbol, the symbol can be checked (and wrapped in an error) early. For the case where a symbol-choice is returned, the error wrapping can only happen where the choice is ultimately resolved.