2

If I have:

import demo::lang::Exp::Concrete::WithLayout::Syntax;
if ((Exp)`<IntegerLiteral e> + <IntegerLiteral e>` := (Exp)`5 + 6`) { 
    println(e);
}

This prints 6. Is this a possible bug or a design decision, e.g. because of performance considerations? It should of course not print anything, since e cannot be matched to both 5 and 6. This is, however, in contrast to matching with ADTs, where this is caught, i.e.:

data ExpNum = numb(int n) | add(ExpNum e1, ExpNum e2);
if (add(numb(x), numb(x)) := add(numb(5), numb(6))) { println(x); }

Will not print a number, while it does print a number when using numb(5) instead of numb(6).

Ps. I ran the example both from Rascal source using Eclipse Plug-in Development (using a forked version merged with the latest version of Rascal), as well as on two machines using the official Eclipse plugin. The plugin, however, returned the following on both machines:

|stdin:///|(4,46,<1,4>,<1,50>): Java compilation failed due to with classpath [/home/wouter/eclipse//plugins/org.eclipse.equinox.launcher_1.3.100.v20150511-1540.jar]: package org.eclipse.imp.pdb.facts.type does not exist

The reason why I am asking is because, somewhat similarly, ConcreteListVariablePattern automatically throws a RedeclaredVariable-exception without checking if the match result's value is equivalent to the variable in the environment, in contrast to e.g. QualifiedNamePattern which checks if the result is equivalent to the value in the environment in case of a readily declared variable.

Thank you!

  • Can you provide examples for the other cases that you mention? – Paul Klint Aug 17 '15 at 22:50
  • The other case was about having e.g. `\`{Param ","}* paramDups {Param ","} paramDups\`` in a syntax. This will assumably either throw an exception or behave erroneous like the example above (I am in the process of fixing my forked Rascal version, so I am not 100% sure). What I am curious about, however, is why variable reuse is not supported for variables in concrete patterns, while it is supported for variables in non-concrete patterns (e.g. the `numb(x), numb(x)`-example), as you state in your answer that it is supposed to throw a `RedeclaredVariable`-exception. – Wouter Nederhof Aug 19 '15 at 20:46

1 Answers1

3

This is definitely a bug: the variable e is declared twice (without warning), the match succeeds and the binding to second e is printed. Expected behavior would be that a RedeclaredVariable exception is thrown.

A work around is as follows:

if ((Exp)`<IntegerLiteral e1> + <IntegerLiteral e2>` := (Exp)`5 + 6` && e1 == e2) { 
    println(e1);
}
Paul Klint
  • 1,418
  • 7
  • 12