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

T in typedesc[T] treated as value in templates #17240

Closed
SolitudeSF opened this issue Mar 2, 2021 · 1 comment · Fixed by #22535
Closed

T in typedesc[T] treated as value in templates #17240

SolitudeSF opened this issue Mar 2, 2021 · 1 comment · Fixed by #22535

Comments

@SolitudeSF
Copy link
Contributor

Example

func to(c: int, t: typedesc[float]): t = discard

template converted[I, T](i: seq[I], t: typedesc[T]): seq[T] =
  var result = newSeq[T]()
  result[0] = i[0].to(T)
  result

echo newSeq[int]().converted(float)

Current Output

/home/solitude/test.nim(23, 19) Error: type mismatch: got <int, float>
but expected one of:
func to(c: int; t: typedesc[float]): t:type
  first type mismatch at position: 2
  required type for t: typedesc[float]
  but expression 'T' is of type: float

expression: to(newSeq(Natural(0))[0], T)

Expected Output

compiles

Possible Solution

using typedesc parameter itself like i[0].to(t) works.

$ nim -v
Nim Compiler Version 1.5.1 [Linux: amd64]
Compiled at 2021-03-01
Copyright (c) 2006-2021 by Andreas Rumpf

git hash: d27c0e2982d19ae2203b40a3227c62ea32d11b72
@timotheecour
Copy link
Member

timotheecour commented Mar 2, 2021

possible duplicate of #13527 (which is more general and explains root cause)

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.

2 participants