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
405 stars 78 forks source link

Text based ValueIO cannot read ADT values that have overloaded constructors #386

Open wouterkwakernaak opened 10 years ago

wouterkwakernaak commented 10 years ago

The type Declaration of library lang::java::m3::AST has overloaded constructors. ValueIO can write Declaration values but cannot read them in case the value is constructed using one or more overloaded constructors.

See the following example code:

module SomeModule

import ValueIO;
import lang::java::m3::AST;

loc file = ...;
loc smallJavaFile = ...;

public void storeAndReadAstFromFile() {
   Declaration ast = createAstFromFile(smallJavaFile, true);
   writeTextValueFile(file, ast);
   readTextValueFile(#Declaration, file);
}

throws

|rascal://ValueIO|(883,182,<29,0>,<32,60>): Java("OverloadingNotSupportedException","Overloading is not supported (Declaration.compilationUnit)") at org.eclipse.imp.pdb.facts.io.StandardTextReader.readConstructor(|file:///StandardTextReader.java|(0,0,<339,0>,<339,0>)) at org.eclipse.imp.pdb.facts.io.StandardTextReader.readValue(|file:///StandardTextReader.java|(0,0,<110,0>,<110,0>)) at org.eclipse.imp.pdb.facts.io.StandardTextReader.read(|file:///StandardTextReader.java|(0,0,<94,0>,<94,0>)) at org.rascalmpl.library.Prelude.readTextValueFile(|file:///Prelude.java|(0,0,<3192,0>,<3192,0>)) at sun.reflect.NativeMethodAccessorImpl.invoke0(|file:///NativeMethodAccessorImpl.java|(0,0,<0,0>,<0,0>)) at readTextValueFile(|rascal://Benchmarks::ASTBenchmark|(1474,4,<54,49>,<54,53>)) at runAndPrintAnASTBenchmark(|rascal://Benchmarks::ASTBenchmark|(584,24,<18,36>,<18,60>)) at main(|rascal://Benchmarks::Benchmarks|(190,28,<9,1>,<9,29>)) at $shell$(|rascal://Benchmarks::Util|(152,63,<8,27>,<8,90>))

this exception is thrown in line 339 of StandardTextReader.java of pdb.values.

DavyLandman commented 10 years ago

Also the case for binary?

mahills commented 10 years ago

Binary should be fine -- the problem is in the text reader, since it needs to look up the correct constructor based just on the name and it makes no attempt to resolve overloading. This is a known limitation (at least internally, it isn't documented in the library documentation as far as I know) -- it came up a couple of months ago on another issue, and I had to work around it with the PHP work since I originally had different constructors that had the same name and that were clashing. Binary isn't an issue since it doesn't have to do any resolution, it just deserializes the existing constructor information.

Davy Landman mailto:notifications@github.com November 8, 2013 at 9:14 AM

Also the case for binary?

— Reply to this email directly or view it on GitHub https://github.com/cwi-swat/rascal/issues/386#issuecomment-28065077.

wouterkwakernaak commented 10 years ago

Binary works indeed, I would however also like it to work for text