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

ICE quote do - var not init #10624

Closed
mratsim opened this issue Feb 10, 2019 · 1 comment
Closed

ICE quote do - var not init #10624

mratsim opened this issue Feb 10, 2019 · 1 comment

Comments

@mratsim
Copy link
Collaborator

mratsim commented Feb 10, 2019

I forgot quotation in the following quote do snippet and it crashed the compiler (latest devel)

import macros

type
  Expr = object of RootObj

  Input[T] = object of Expr
    value: NimNode

  AddExpr[T1, T2] = object of Expr
    lhs: T1
    rhs: T2

proc input[T](value: NimNode): Input[T] =
  Input[T](value: value)

proc `+`[T1, T2](lhs: T1, rhs: T2): AddExpr[T1, T2] =
  result.lhs = lhs
  result.rhs = rhs

proc eval[T](input: Input[T]): NimNode =
  input.value

proc eval(addExpr: AddExpr): NimNode =
  newCall(ident"+", addExpr.lhs.eval, addExpr.rhs.eval)

macro foo(a, b: int): untyped =
  
  let ia = input[int](a)
  let ib = input[int](b)
  
  let c = ia + ib + ia
  echo c.repr
  let val_C = eval(c)

  echo val_C.repr

  result = quote do: val_C # Correct would be `val_C`

let c = foo(1, 3)
(lhs: (lhs: (value: 1), rhs: (value: 3)), rhs: (value: 1))
`+`(`+`(1, 3), 1)
obj_algebra_ast.nim(37, 12) Error: internal error: expr: var not init val_C_163266
No stack traceback available
To create a stacktrace, rerun compilation with ./koch temp c <file>
@LemonBoy
Copy link
Contributor

Duplicate of #8573, closing.

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