usethesource / rascal

The implementation of the Rascal meta-programming language (including interpreter, type checker, parser generator, compiler and JVM based run-time system)
http://www.rascal-mpl.org
Other
406 stars 78 forks source link

Illegal type error during pattern matching #852

Open BertLisser opened 9 years ago

BertLisser commented 9 years ago

I expect that the following code runs correctly. But it does not.

module experiments::vis2::Tst

import Prelude;
import util::Math;

data D = q(value \value=3)|r(value \value="OK");

public void main() {
   for (int i<-[0..10]) {
      D d = arbReal()<.5?q():r();
      if (str v :=d.\value) println(v); else println("Also OK");
      }
   }

Output:

OK
OK
OK
OK
|project://rascal/src/org/rascalmpl/library/experiments/vis2/Tst.rsc|(91,1,<6,24>,<6,25>): 
Expected str, but got int

However the following code runs correctly.

module experiments::vis2::Tst
import Prelude;
import util::Math;

data D = q(value \value)|r(value \value);

public void main() {
   for (int i<-[0..10]) {
      D d = arbReal()<.5?q(3):r("OK");
      if (str v :=d.\value) println(v); else println("Also OK");
      }
   }

Output

Also OK
OK
OK
OK
OK
Also OK
Also OK
OK
OK
OK
PaulKlint commented 9 years ago

Note that the error is in the data declaration!

I suspect this is caused by a bug in the interpreter in handling the keyword parameter in the first example.

Example runs fine when compiled.