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
404 stars 77 forks source link

Field access on an unimported referenced data type exposes an internal error #1243

Closed rodinaarssen closed 5 years ago

rodinaarssen commented 5 years ago
module A
data D = d(int i);
D getD() = d(1);
module B
import A;
data E = e(D d);
E foo() = e(getD());
rascal>import B;
ok
rascal>foo().d
D: d(1)
rascal>foo().d.i
io.usethesource.vallang.exceptions.UndeclaredAbstractDataTypeException: D is not registered
(internal error)
        at $root$(|main://$root$|)

io.usethesource.vallang.exceptions.UndeclaredAbstractDataTypeException: D is not registered
        at io.usethesource.vallang.type.AbstractDataType.hasField(AbstractDataType.java:250)
        at org.rascalmpl.interpreter.result.ConstructorResult.fieldAccess(ConstructorResult.java:95)
        at org.rascalmpl.semantics.dynamic.Expression$FieldAccess.interpret(Expression.java:872)
        at org.rascalmpl.semantics.dynamic.Command$Expression.interpret(Command.java:61)
        at org.rascalmpl.interpreter.Evaluator.eval(Evaluator.java:1087)
        at org.rascalmpl.interpreter.Evaluator.eval(Evaluator.java:957)
        at org.rascalmpl.interpreter.Evaluator.eval(Evaluator.java:912)
        at org.rascalmpl.repl.RascalInterpreterREPL.evalStatement(RascalInterpreterREPL.java:137)
        at org.rascalmpl.eclipse.repl.RascalTerminalConnector$2.evalStatement(RascalTerminalConnector.java:338)
        at org.rascalmpl.repl.BaseRascalREPL.handleInput(BaseRascalREPL.java:112)
        at org.rascalmpl.eclipse.repl.RascalTerminalConnector$2.handleInput(RascalTerminalConnector.java:293)
        at org.rascalmpl.repl.BaseREPL.handleInput(BaseREPL.java:164)
        at org.rascalmpl.repl.BaseREPL.run(BaseREPL.java:325)
        at org.rascalmpl.eclipse.repl.RascalTerminalConnector$1.run(RascalTerminalConnector.java:135)

ok
rascal>import A;
ok
rascal>foo().d.i
int: 1
TimSoethout commented 5 years ago

I had a similar error with o.usethesource.vallang.exceptions.UndeclaredAbstractDataTypeException: Tree is not registered (internal error) at $root$(|main://$root$|)

import ParseTree; in the offending file solved it and exposes the real error: |project://rebel-psac-static/src/psac/Analysis.rsc|(1036,1,<38,20>,<38,21>): Undeclared field: spec for Tree on a line where I try to access an undefined field indeed.

jurgenvinju commented 5 years ago

current suspect: typestore of module B is lacking proper import of module A. The code for ConstructorResult.fieldAccess seems in order.

rodinaarssen commented 5 years ago

Module B is fine. It's about the interpreter (or a module C that only imports module B) not having imported module A.

On a sidenote: the type checker also flags this as an error on such a module C.

jurgenvinju commented 5 years ago

Right, I wasn't clear. Internally the environment in the interpreter holds an object (a TypeStore) which should import the typestores of other modules. It seems that it doesn't and thus misses the declaration. That's just a guess though. Have to look more into it.

jurgenvinju commented 5 years ago

Right. Now I read your comment better. It's because imports aren't transitive. Duh. That's an easy fix to get the right error message on the screen.