Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiler crash related to static[T] #14053

Closed
GULPF opened this issue Apr 21, 2020 · 5 comments · Fixed by #24028
Closed

Compiler crash related to static[T] #14053

GULPF opened this issue Apr 21, 2020 · 5 comments · Fixed by #24028

Comments

@GULPF
Copy link
Member

GULPF commented Apr 21, 2020

Updated example (from the comment below)

template returnType(value: static[int]): typedesc =
    when value == 1:
        int
    else:
        float

proc fun*(value: static[int]): returnType(value) =
    discard

echo fun(1)

Original Example

template returnType(value: static[int]): typedesc =
    int

proc fun*(value: static[int]): returnType(value) =
    discard

Current Output

SIGSEGV: Illegal storage access. (Attempt to read from nil?)

koch temp output

/nim/compiler/nim.nim(104) nim
/nim/compiler/nim.nim(81) handleCmdLine
/nim/compiler/cmdlinehelper.nim(91) loadConfigsAndRunMainCommand
/nim/compiler/main.nim(190) mainCommand
/nim/compiler/main.nim(92) commandCompileToC
/nim/compiler/modules.nim(143) compileProject
/nim/compiler/modules.nim(84) compileModule
/nim/compiler/passes.nim(216) processModule
/nim/compiler/passes.nim(86) processTopLevelStmt
/nim/compiler/sem.nim(604) myProcess
/nim/compiler/sem.nim(572) semStmtAndGenerateGenerics
/nim/compiler/semstmts.nim(2308) semStmt
/nim/compiler/semexprs.nim(1014) semExprNoType
/nim/compiler/semexprs.nim(2794) semExpr
/nim/compiler/semstmts.nim(2087) semProc
/nim/compiler/semstmts.nim(1899) semProcAux
/nim/compiler/semstmts.nim(1429) semParamList
/nim/compiler/semtypes.nim(1283) semProcTypeNode
/nim/compiler/semtypes.nim(1788) semTypeNode
/nim/compiler/semtypes.nim(1484) semTypeExpr
/nim/compiler/semexprs.nim(76) semExprWithType
/nim/compiler/semexprs.nim(67) semExprCheck
/nim/compiler/semexprs.nim(2673) semExpr
/nim/compiler/semexprs.nim(995) semDirectOp
/nim/compiler/semexprs.nim(844) semOverloadedCallAnalyseEffects
/nim/compiler/semcall.nim(562) semOverloadedCall
/nim/compiler/semcall.nim(530) semResolvedCall
/nim/compiler/ast.nim(1092) add
/nim/lib/system/assertions.nim(29) failedAssertImpl
/nim/lib/system/assertions.nim(22) raiseAssert
/nim/lib/system/fatal.nim(49) sysFatal
Error: unhandled exception: /nim/compiler/ast.nim(1092, 10) `
not (son == nil)`  [AssertionError]
FAILURE
@cooldome
Copy link
Member

It is not really static[T] , you currently can't use calls in proc return type. Would be nice to get fixed

@GULPF
Copy link
Member Author

GULPF commented Apr 28, 2020

@cooldome It's not caused by using a call in a return type, the same errors occurs if the call is used for a parameter type:

template returnType(value: static[int]): typedesc =
    int

proc fun*(value: static[int], _: returnType(value)) =
    discard

If the call does not reference another parameter however it works for both parameter types and return types.

@narimiran
Copy link
Member

The example successfully compiles with Nim devel v1.3.5 on my machine. @GULPF, can you confirm?

@GULPF
Copy link
Member Author

GULPF commented Jul 10, 2020

The original example now compiles, but attempting to use value inside returnType in a compile time context fails (but doesn't crash):

template returnType(value: static[int]): typedesc =
    when value == 1:
        int
    else:
        float

proc fun*(value: static[int]): returnType(value) =
    discard

echo fun(1)

Output:

Error: cannot evaluate at compile time: value

I can update the issue or create a new one

@metagn
Copy link
Collaborator

metagn commented Aug 27, 2024

Works now #24005

metagn added a commit to metagn/Nim that referenced this issue Aug 29, 2024
@Araq Araq closed this as completed in fc853cb Aug 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants