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.63k stars 1.47k forks source link

type mismatch when use nnkSym as typedesc parameter #20005

Open gabbhack opened 2 years ago

gabbhack commented 2 years ago

Example

import std/macros

proc withTypedesc(T: typedesc): T = discard

macro genVar(name: untyped) =
  newVarStmt(
    name,
    newCall(
      bindSym("withTypedesc"), bindSym "int"
    )
  )

genVar foo
echo foo

https://play.nim-lang.org/#ix=4448

Current Output

Error: type mismatch: got <int>
but expected one of:
proc withTypedesc(T: typedesc): T:type
  first type mismatch at position: 1
  required type for T: typedesc
  but expression 'int' is of type: int

expression: withTypedesc(int)

Expected Output

none(int)
$ nim -v
Nim Compiler Version 1.6.6 [Windows: amd64]
Compiled at 2022-05-05
Copyright (c) 2006-2021 by Andreas Rumpf

active boot switches: -d:release
metagn commented 1 month ago

The symbol int has type int which isn't updated by prepareOperand because it's not nil type, workaround is newPar(bindSym"int")