Skip to content

js compile crash for generic proc that has return type marked by exportc #25229

@litlighilit

Description

@litlighilit

Nim Version

2.3.1
2.*

Description

static: assert defined(js)
proc f(_: SomeFloat): int{.exportc.} = discard

Current Output

Error: unhandled exception: index 7 not in 0 .. 6 [IndexDefect]

Expected Output

(compiles with no error)

Known Workarounds

Delete one of these properties:

  • exportc
  • generic
  • has return type
  • (js backend)

Additional Information

real world example: nimpylib/nimpylib#43

Traceback:

compiler/jsgen.nim:3063

genSym accesses n[namePos] (and the line above it checks proc has sfExportc and no sfCompilerProc)
→ genProcForSymIfNeeded →attachProc →

genProc checks
if prc.typ.returnType != nil and sfPure notin prc.flags:

and then call gen(p, prc.ast[resultPos], a) where prc is n[namePos]

But n[namePos].sym.ast.sons.len != 8

So n[namePos].sym.ast[resultPos](resultPos = 7) raises IndexDefect

compiler/pipelines

However, we can find that even in C backend, the node that'll be passed as n[namePos].sym.ast in JS backend still doesn't contain Item#7

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions