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

Macro + static: type mismatch in type declaration but not in var declaration #7230

Closed
mratsim opened this issue Feb 17, 2018 · 0 comments
Closed

Comments

@mratsim
Copy link
Collaborator

mratsim commented Feb 17, 2018

I'm trying to get some fixed multi-precision integer working.

While trying to create aliases, it seems like macro do not like static arguments in a type declaration context. It works fine however in a variable declaration context:

import macros, typetraits

macro getBase*(bits: static[int]): untyped =
  if bits == 128:
    result = newTree(nnkBracketExpr, ident("MpUintBase"), ident("uint64"))
  else:
    result = newTree(nnkBracketExpr, ident("MpUintBase"), ident("uint32"))

type
  BaseUint* = SomeUnsignedInt or MpUintBase

  MpUintBase*[BaseUint] = object
      lo*, hi*: BaseUint

  ## This gets type mismatch
  MpUint*[bits: static[int]] = getBase(bits)

## This works fine
var foo: getBase(64)
echo foo.type.name
@mratsim mratsim changed the title Static: compiler internal error: getTypeDescAux(tyNone) Macro + static: type mismatch in type declaration but not in var declaration Feb 17, 2018
zah added a commit to status-im/Nim that referenced this issue Mar 21, 2018
@Araq Araq closed this as completed in 121b9e2 Mar 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants