racket / rhombus-prototype

Brainstorming and draft proposals for Rhombus

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Possible bug with repeated constants in macro templates

jackfirth opened this issue · comments

This code:

#lang rhombus/and_meta

defn.macro 'foo: $expr; ...':
  let [index, ...]:
    for:
      each i: 0..List.length(List(expr, ...))
      i
  'List($index, ...)'

...fails to compile, raising this error:

index28: unbound identifier;
 also, no #%top syntax transformer is bound in the transformer phase
  context...:
   #(1188811 macro) [common scopes]
  other binding...:
   local
   #(1188787 use-site) [common scopes]
  common scopes...:
   #(1188757 intdef) #(1188790 macro) #(1188791 macro) in: index28

I'm pretty sure this is a bug, but I might just be holding it wrong. This came up for me because I'm trying to write an enum macro that turns this:

enum Direction:
  Up
  Down
  Left
  Right

Into this:

class Direction(index :: NonnegativeInteger):
  def Up = Direction(0)
  def Down = Direction(1)
  def Left = Direction(2)
  def Right = Direction(3)

It looks like the problem is in the interaction of let and repetition, and this smaller example has the same problem:

begin:
  let [index, ...]: [1, 2, 3]
  [index, ...]

Until this is fixed, you could work around the bug by using def instead of let.