File name influences JastAdd code generation

Issue #322 resolved
Görel Hedin created an issue

Idriss has encountered a bug in JastAdd, see attachment. He gets a compilation error when trying to define a collection attribute on an interface. But if he changes the file name from s.jrag to r.jrag, the compilation gets through. He has narrowed down the problem to a very small example.

I tried it on my computer and I got the same compilation error for s.jrag, and also got the error if I changed the filename to r.jrag. But if I changed the filename to z.jrag, the compilation error disappeared.

I guess this problem is related to side effects in aspect weaving as discussed in

Comments (6)

  1. Jesper Öqvist

    I tried running JastAdd on the files in the provided zip file and I get a JastAdd error when “s.jrag” is placed before “Test.jrag” on the JastAdd command line (regardless of what I rename the s.jrag file to):

    java -jar ~/git/jastadd2/jastadd2.jar --package=lang --o=tmp Grammar.ast a.jrag Test.jrag
    Error: Can not add collection attribute Collection<String> set to unknown class I in a.jrag at line 5

  2. Jesper Öqvist

    There is some kind of order dependency between the public interface I {} line in Test.jrag and the collection declaration in s.jrag.

    To fix this, the interface declaration should be added to the AST declarations before processing collection attributes. I’m not sure if this is easy to fix nor not.

  3. Jesper Öqvist

    A hacky solution to fix this particular example without changing JastAdd is to just add public interface I {} before the collection attribute (having 2 copies of the interface declaration):

        public interface I { }
        coll Collection<String> I.set() [new HashSet<String>()] with add;

  4. Niklas Fors

    I think that Idriss has a solution to this problem so that collection attributes are handled similar to other kinds of attributes (not weaved during parsing). But he hasn’t created a PR yet.

  5. Jesper Öqvist

    Here is a single-file test for this bug.

    import java.util.*;
    aspect Test {
      coll Collection<String> I.set();
      public interface I { }
      A implements I;

  6. Log in to comment