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

issues using generic parameters in template #6340

Closed
jcosborn opened this issue Sep 6, 2017 · 2 comments · Fixed by #22535
Closed

issues using generic parameters in template #6340

jcosborn opened this issue Sep 6, 2017 · 2 comments · Fixed by #22535

Comments

@jcosborn
Copy link
Contributor

jcosborn commented Sep 6, 2017

In template fooT[T](x: A[T]) calling foo(T), which is a proc, crashes the compiler and calling fooT(T), which is a template, matches the int overload instead of typedesc[int].

type
  A[T] = object
    v: T

proc foo(x: int) = echo "int"
proc foo(x: typedesc[int]) = echo "typedesc[int]"
template fooT(x: int) = echo "int"
template fooT(x: typedesc[int]) = echo "typedesc[int]"

proc foo[T](x: A[T]) =
  foo(T)   # typedesc[int]  (correct)
  fooT(T)  # typedesc[int]  (correct)

template fooT[T](x: A[T]) =
  foo(T)   # typedescparam.nim(20, 5) Error: internal error: expr(skType); unknown symbol
  fooT(T)  # int  (should be typedesc[int])

var x: A[int]
foo(x)
fooT(x)
@jxy
Copy link
Contributor

jxy commented Sep 7, 2017

Right. I have been using workarounds like this:

type
  A[T] = object
    v: T

proc foo(x: int) = echo "int"
proc foo(x: typedesc[int]) = echo "typedesc[int]"
template fooT(x: int) = echo "int"
template fooT(x: typedesc[int]) = echo "typedesc[int]"

proc foo(x: A) =
  foo(x.T)
  fooT(x.T)

template fooT(x: A) =
  foo(x.T)
  fooT(x.T)

var x: A[int]
foo(x)
fooT(x)

@zah zah self-assigned this Sep 7, 2017
@ghost ghost added the Compiler Crash label Apr 12, 2018
@genotrance
Copy link
Contributor

Still crashes with #head, full stacktrace below.

-------- SNIPPET --------
type
  A[T] = object
    v: T

proc foo(x: int) = echo "int"
proc foo(x: typedesc[int]) = echo "typedesc[int]"
template fooT(x: int) = echo "int"
template fooT(x: typedesc[int]) = echo "typedesc[int]"

proc foo[T](x: A[T]) =
  foo(T)   # typedesc[int]  (correct)
  fooT(T)  # typedesc[int]  (correct)

template fooT[T](x: A[T]) =
  foo(T)   # typedescparam.nim(20, 5) Error: internal error: expr(skType); unknown symbol
  fooT(T)  # int  (should be typedesc[int])

var x: A[int]
foo(x)
fooT(x)
-------------------------

-------- OUTPUT --------
Hint: used config file 'c:\users\gt\Desktop\DL\programming\nimdevel\config\nim.cfg' [Conf]
Hint: system [Processing]
Hint: temp [Processing]
temp.nim(20, 5) Error: internal error: expr(skType); unknown symbol
No stack traceback available
To create a stacktrace, rerun compilation with ./koch temp c <file>
------------------------

-------- NIMTEMP --------
Hint: used config file 'c:\users\gt\Desktop\DL\programming\nimdevel\config\nim.cfg' [Conf]
Hint: system [Processing]
Hint: temp [Processing]
temp.nim(20, 5) Error: internal error: expr(skType); unknown symbol
Traceback (most recent call last)
nim.nim(133)             nim
nim.nim(97)              handleCmdLine
main.nim(162)            mainCommand
main.nim(73)             commandCompileToC
modules.nim(124)         compileProject
modules.nim(71)          compileModule
passes.nim(194)          processModule
passes.nim(103)          processTopLevelStmt
cgen.nim(1379)           myProcess
ccgstmts.nim(1150)       genStmts
ccgexprs.nim(2257)       expr
ccgexprs.nim(2041)       genStmtList
ccgstmts.nim(1150)       genStmts
ccgexprs.nim(2223)       expr
ccgcalls.nim(548)        genCall
ccgcalls.nim(187)        genPrefixCall
ccgcalls.nim(170)        genArg
cgen.nim(496)            initLocExprSingleUse
ccgexprs.nim(2204)       expr
msgs.nim(524)            internalError
msgs.nim(495)            liMessage
msgs.nim(324)            handleError
msgs.nim(314)            quit
-------------------------

-------- VERSION --------
Nim Compiler Version 0.18.1 [Windows: i386]
Compiled at 2018-07-02
Copyright (c) 2006-2018 by Andreas Rumpf

git hash: d1f983b37cf1b0aa03b1424c3cca9d4212558db9
active boot switches: -d:release
-------------------------

metagn added a commit to metagn/Nim that referenced this issue Aug 23, 2023
metagn added a commit to metagn/Nim that referenced this issue Aug 25, 2023
Araq pushed a commit that referenced this issue Aug 25, 2023
* fix generic param substitution in templates

fixes #13527, fixes #17240, fixes #6340, fixes #20033, fixes #19576, fixes #19076

* fix bare except in test, test updated packages in CI
narimiran pushed a commit that referenced this issue Dec 1, 2023
* fix generic param substitution in templates

fixes #13527, fixes #17240, fixes #6340, fixes #20033, fixes #19576, fixes #19076

* fix bare except in test, test updated packages in CI

(cherry picked from commit 1cc4d3f)
narimiran pushed a commit that referenced this issue Dec 1, 2023
* fix generic param substitution in templates

fixes #13527, fixes #17240, fixes #6340, fixes #20033, fixes #19576, fixes #19076

* fix bare except in test, test updated packages in CI

(cherry picked from commit 1cc4d3f)
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