rhombus-prototype icon indicating copy to clipboard operation
rhombus-prototype copied to clipboard

Nested attributes don’t cooperate well enough with repetition

Open usaoc opened this issue 1 year ago • 0 comments

This is an old known bug, but probably I should open an issue so that someone can take a look at it. Nested attributes are currently handled directly in pattern variables, which are transformers that look for a . followed by the symbolic attribute names. However, the implementation doesn’t cooperate well enough with repetition outside the syntax pattern. Namely, this program works

#lang rhombus
block:
  let [pattern
       | '9 $x $_'
       | '8 $x',
       ...]:
    ['8 1', '9 2 3']
  [x, ...]
  // ['1', '2']

while this doesn’t

#lang rhombus
block:
  let [pattern match
       | '9 $x $_'
       | '8 $x',
       ...]:
    ['8 1', '9 2 3']
  [match.x, ...]
  // x: no such field or method

Two relevant tests in rhombus/tests/syntax-class.rhm are commented out, and the comment suggests that :: has a similar bug. Indeed, this program works

#lang rhombus
block:
  syntax_class SomePattern
  | '9 $x $_'
  | '8 $x'
  let ['$(_ :: SomePattern: open)', ...]:
    ['8 1', '9 2 3']
  [x, ...]
  // ['1', '2']

while this doesn’t

#lang rhombus
block:
  syntax_class SomePattern
  | '9 $x $_'
  | '8 $x'
  let ['$(match :: SomePattern)', ...]:
    ['8 1', '9 2 3']
  [match.x, ...]
  // x: no such field or method

usaoc avatar Aug 07 '24 07:08 usaoc