Skip to content

SIGSEGV when return type depends on a static[T] parameter #8545

Closed
@timotheecour

Description

@timotheecour

BUG: case2 below should work, but it gives SIGSEGV

template bar(a: static[bool]): untyped = int

when defined(case1):
  # ok
  proc foo(a: static[bool]): auto = 1

when defined(case2):
  # SIGSEGV: see stacktrace in [1]
  proc foo(a: static[bool]): bar(a) = 1

when defined(case3):
  # Error: type mismatch: got <bool> but expected ... static[bool]
  proc foo(a: static[bool]): bar(static[bool](a)) = 1

when defined(case4):
  # Error: expression cannot be cast to static[bool]
  proc foo(a: static[bool]): bar(cast[static[bool]](a)) = 1

echo foo(true)

#[
[1]
/Users/timothee/git_clone/nim/Nim/compiler/nim.nim(133) nim
/Users/timothee/git_clone/nim/Nim/compiler/nim.nim(97) handleCmdLine
/Users/timothee/git_clone/nim/Nim/compiler/main.nim(162) mainCommand
/Users/timothee/git_clone/nim/Nim/compiler/main.nim(73) commandCompileToC
/Users/timothee/git_clone/nim/Nim/compiler/modules.nim(124) compileProject
/Users/timothee/git_clone/nim/Nim/compiler/modules.nim(71) compileModule
/Users/timothee/git_clone/nim/Nim/compiler/passes.nim(194) processModule
/Users/timothee/git_clone/nim/Nim/compiler/passes.nim(103) processTopLevelStmt
/Users/timothee/git_clone/nim/Nim/compiler/sem.nim(592) myProcess
/Users/timothee/git_clone/nim/Nim/compiler/sem.nim(560) semStmtAndGenerateGenerics
/Users/timothee/git_clone/nim/Nim/compiler/semstmts.nim(1891) semStmt
/Users/timothee/git_clone/nim/Nim/compiler/semexprs.nim(912) semExprNoType
/Users/timothee/git_clone/nim/Nim/compiler/semexprs.nim(2444) semExpr
/Users/timothee/git_clone/nim/Nim/compiler/semexprs.nim(2050) semWhen
/Users/timothee/git_clone/nim/Nim/compiler/semexprs.nim(2520) semExpr
/Users/timothee/git_clone/nim/Nim/compiler/semstmts.nim(1832) semStmtList
/Users/timothee/git_clone/nim/Nim/compiler/semexprs.nim(2538) semExpr
/Users/timothee/git_clone/nim/Nim/compiler/semstmts.nim(1682) semProc
/Users/timothee/git_clone/nim/Nim/compiler/semstmts.nim(1508) semProcAux
/Users/timothee/git_clone/nim/Nim/compiler/semstmts.nim(1119) semParamList
/Users/timothee/git_clone/nim/Nim/compiler/semtypes.nim(1110) semProcTypeNode
/Users/timothee/git_clone/nim/Nim/compiler/semtypes.nim(1492) semTypeNode
/Users/timothee/git_clone/nim/Nim/compiler/semtypes.nim(1276) semTypeExpr
/Users/timothee/git_clone/nim/Nim/compiler/semexprs.nim(59) semExprWithType
/Users/timothee/git_clone/nim/Nim/compiler/semexprs.nim(2413) semExpr
/Users/timothee/git_clone/nim/Nim/compiler/semexprs.nim(893) semDirectOp
/Users/timothee/git_clone/nim/Nim/compiler/semexprs.nim(745) semOverloadedCallAnalyseEffects
/Users/timothee/git_clone/nim/Nim/compiler/semcall.nim(467) semOverloadedCall
/Users/timothee/git_clone/nim/Nim/compiler/semcall.nim(435) semResolvedCall
/Users/timothee/git_clone/nim/Nim/compiler/ast.nim(1037) add
/Users/timothee/git_clone/nim/Nim/lib/system.nim(3753) failedAssertImpl
/Users/timothee/git_clone/nim/Nim/lib/system.nim(3746) raiseAssert
/Users/timothee/git_clone/nim/Nim/lib/system.nim(2807) sysFatal
Error: unhandled exception:
not (son == nil)  [AssertionError]

 ]#

NOTE: use case reduced from #8531 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions