nim-lang / Nim

Nim is a statically typed compiled systems programming language. It combines successful concepts from mature languages like Python, Ada and Modula. Its design focuses on efficiency, expressiveness, and elegance (in that order of priority).
https://nim-lang.org
Other
16.54k stars 1.47k forks source link

Async function causes internal error during compilation. #13357

Open FasterSpeeding opened 4 years ago

FasterSpeeding commented 4 years ago

Async function causes Error: internal error: genTypeInfo(tyNil) during compilation to C.

Example

import asyncdispatch
import json

type
    NilType = type(nil)

    Unspecified = ref object

var
    unspecified: Unspecified = Unspecified()

proc `%`(opt: NilType): typeof json.newJNull() =
    return json.newJNull() 

proc modifyChannel*(
        channelID: string,
        name: string | NilType | Unspecified = unspecified,
    ): Future[json.JsonNode] {.async.} =
    var node: json.JsonNode = %*{"id": channelID}
    if name != unspecified:
        node.add("name", %name)
    return node

echo waitFor modifyChannel("9292929", name=nil)
echo waitFor modifyChannel("9292929")

Current Output

Error: internal error: genTypeInfo(tyNil)
No stack traceback available
To create a stacktrace, rerun compilation with ./koch temp c <file>

With the traceback being

Error: internal error: genTypeInfo(tyNil)
Traceback (most recent call last)
C:\Users\Lukec\Documents\VSC\Nim\compiler\nim.nim(118) nim
C:\Users\Lukec\Documents\VSC\Nim\compiler\nim.nim(95) handleCmdLine
C:\Users\Lukec\Documents\VSC\Nim\compiler\cmdlinehelper.nim(105) loadConfigsAndRunMainCommand
C:\Users\Lukec\Documents\VSC\Nim\compiler\main.nim(190) mainCommand
C:\Users\Lukec\Documents\VSC\Nim\compiler\main.nim(92) commandCompileToC
C:\Users\Lukec\Documents\VSC\Nim\compiler\modules.nim(143) compileProject
C:\Users\Lukec\Documents\VSC\Nim\compiler\modules.nim(84) compileModule
C:\Users\Lukec\Documents\VSC\Nim\compiler\passes.nim(210) processModule
C:\Users\Lukec\Documents\VSC\Nim\compiler\passes.nim(86) processTopLevelStmt
C:\Users\Lukec\Documents\VSC\Nim\compiler\cgen.nim(1891) myProcess
C:\Users\Lukec\Documents\VSC\Nim\compiler\cgen.nim(974) genProcBody
C:\Users\Lukec\Documents\VSC\Nim\compiler\ccgstmts.nim(1417) genStmts
C:\Users\Lukec\Documents\VSC\Nim\compiler\ccgexprs.nim(2610) expr
C:\Users\Lukec\Documents\VSC\Nim\compiler\ccgexprs.nim(2272) genMagicExpr
C:\Users\Lukec\Documents\VSC\Nim\compiler\ccgexprs.nim(1055) genEcho
C:\Users\Lukec\Documents\VSC\Nim\compiler\cgen.nim(602) initLocExpr
C:\Users\Lukec\Documents\VSC\Nim\compiler\ccgexprs.nim(2630) expr
C:\Users\Lukec\Documents\VSC\Nim\compiler\ccgexprs.nim(2409) genArrayConstr
C:\Users\Lukec\Documents\VSC\Nim\compiler\ccgexprs.nim(2618) expr
C:\Users\Lukec\Documents\VSC\Nim\compiler\ccgcalls.nim(568) genCall
C:\Users\Lukec\Documents\VSC\Nim\compiler\ccgcalls.nim(194) genPrefixCall
C:\Users\Lukec\Documents\VSC\Nim\compiler\ccgcalls.nim(177) genArg
C:\Users\Lukec\Documents\VSC\Nim\compiler\cgen.nim(615) initLocExprSingleUse
C:\Users\Lukec\Documents\VSC\Nim\compiler\ccgexprs.nim(2618) expr
C:\Users\Lukec\Documents\VSC\Nim\compiler\ccgcalls.nim(568) genCall
C:\Users\Lukec\Documents\VSC\Nim\compiler\ccgcalls.nim(194) genPrefixCall
C:\Users\Lukec\Documents\VSC\Nim\compiler\ccgcalls.nim(177) genArg
C:\Users\Lukec\Documents\VSC\Nim\compiler\cgen.nim(615) initLocExprSingleUse
C:\Users\Lukec\Documents\VSC\Nim\compiler\ccgexprs.nim(2618) expr
C:\Users\Lukec\Documents\VSC\Nim\compiler\ccgcalls.nim(568) genCall
C:\Users\Lukec\Documents\VSC\Nim\compiler\ccgcalls.nim(207) genPrefixCall
C:\Users\Lukec\Documents\VSC\Nim\compiler\cgen.nim(602) initLocExpr
C:\Users\Lukec\Documents\VSC\Nim\compiler\ccgexprs.nim(2548) expr
C:\Users\Lukec\Documents\VSC\Nim\compiler\cgen.nim(1199) genProc
C:\Users\Lukec\Documents\VSC\Nim\compiler\cgen.nim(1164) genProcNoForward
C:\Users\Lukec\Documents\VSC\Nim\compiler\cgen.nim(1030) genProcAux
C:\Users\Lukec\Documents\VSC\Nim\compiler\cgen.nim(974) genProcBody
C:\Users\Lukec\Documents\VSC\Nim\compiler\ccgstmts.nim(1417) genStmts
C:\Users\Lukec\Documents\VSC\Nim\compiler\ccgexprs.nim(2648) expr
C:\Users\Lukec\Documents\VSC\Nim\compiler\ccgexprs.nim(2433) genStmtList
C:\Users\Lukec\Documents\VSC\Nim\compiler\ccgstmts.nim(1417) genStmts
C:\Users\Lukec\Documents\VSC\Nim\compiler\ccgexprs.nim(2648) expr
C:\Users\Lukec\Documents\VSC\Nim\compiler\ccgexprs.nim(2433) genStmtList
C:\Users\Lukec\Documents\VSC\Nim\compiler\ccgstmts.nim(1417) genStmts
C:\Users\Lukec\Documents\VSC\Nim\compiler\ccgexprs.nim(2610) expr
C:\Users\Lukec\Documents\VSC\Nim\compiler\ccgexprs.nim(2182) genMagicExpr
C:\Users\Lukec\Documents\VSC\Nim\compiler\ccgexprs.nim(1263) genNew
C:\Users\Lukec\Documents\VSC\Nim\compiler\ccgexprs.nim(1220) rawGenNew
C:\Users\Lukec\Documents\VSC\Nim\compiler\ccgtypes.nim(1378) genTypeInfo
C:\Users\Lukec\Documents\VSC\Nim\compiler\ccgtypes.nim(1040) genTypeInfoAux
C:\Users\Lukec\Documents\VSC\Nim\compiler\ccgtypes.nim(1387) genTypeInfo
C:\Users\Lukec\Documents\VSC\Nim\compiler\ccgtypes.nim(1149) genObjectInfo
C:\Users\Lukec\Documents\VSC\Nim\compiler\ccgtypes.nim(1081) genObjectFields
C:\Users\Lukec\Documents\VSC\Nim\compiler\ccgtypes.nim(1136) genObjectFields
C:\Users\Lukec\Documents\VSC\Nim\compiler\ccgtypes.nim(1343) genTypeInfo
C:\Users\Lukec\Documents\VSC\Nim\compiler\ccgtypes.nim(1394) genTypeInfo
C:\Users\Lukec\Documents\VSC\Nim\compiler\msgs.nim(565) internalError
C:\Users\Lukec\Documents\VSC\Nim\compiler\msgs.nim(443) rawMessage
C:\Users\Lukec\Documents\VSC\Nim\compiler\msgs.nim(440) rawMessage
C:\Users\Lukec\Documents\VSC\Nim\compiler\msgs.nim(356) handleError
C:\Users\Lukec\Documents\VSC\Nim\compiler\msgs.nim(346) quit
FAILURE

Expected Output

{"id":"9292929","name":null}
{"id":"9292929"}

Possible Solution

Additional Information

git hash: 79ec8c257183e01c01811a34e3930de7814756fb

shirleyquirk commented 4 years ago

Using TinyRtti (calls genTypeInfoV2 instead) this compiles and runs, i.e. --gc:arc --gc:destructors --gc:orc all work