metaborg / nabl

Spoofax' Name Binding Language
Apache License 2.0
7 stars 12 forks source link

Retrieving astId of list term gets astId of first element instead #111

Open RvanBaarle opened 1 year ago

RvanBaarle commented 1 year ago

Bug description

Versions Spoofax version: Spoofax 3 (local branch at https://github.com/RvanBaarle/spoofax-pie/develop), using nabl repository at commit 36b9fad6 Statix setup: single-file

Steps to reproduce the behavior See this stxtest file:

resolve

  bugged([Test(), Other()])

signature
  sorts Test
  constructors
    Test : Test
    Other : Test

rules

  bugged : list(Test)
  bugged(a@[h|t]) :- {id1 id2 id3}
    astId(a, id1),
    astId(h, id2),
    astId(t, id3),
    try { false } | note$[list id: [id1]   head id: [id2]   tail id: [id3]].

  bugged2 : list(Test)
  bugged2(a) :- {id}
    astId(a, id),
    try { false } | note$[list id: [id]].

Observed behavior The ids for term a and h are both 5. When compared to the output of Show Analyzed AST this appears to be the id corresponding to term h. The bugged2 rule shows that this issue also occurs when the [h|t] syntax isn't used.

Expected behavior The id for term a should be the id for the list term, corresponding to what's shown by Show Analyzed AST. Instead of the id of the head term of the list term.

Additional context This bug makes it impossible to assign properties (@x.prop := y) to list terms, as it'll get assigned to the head term instead.

AZWN commented 1 year ago

Indeed, this is a strange bug. How urgent is it for your progress?

RvanBaarle commented 1 year ago

It's not urgent, I worked around it by defining an extra AST term encapsulating the list.