Why are static type errors in this example code only reported at run-time by Rascal?

StackOverflow https://stackoverflow.com/questions/16164843

  •  11-04-2022
  •  | 
  •  

Question

According to the Rascal documentation, the language is statically typed. However the type errors are only reported on runtime.

For example, when I create this module, I expect a type error because I am assigning a real to an int variable:

module Example

void example() {
  int x = 1.0;
  println(x);
}

When I import the module on the REPL, and finally run the function:

rascal>import Example;
ok
rascal>example()
|project://Test/src/Example.rsc|(39,7,<4,6>,<4,13>): Expected int, but got real
☞ Advice
Was it helpful?

Solution

The documentation is running ahead of the plan for Rascal. Rascal has a type system that can be statically checked, but the type checker is not integrated yet.

Currently the interpreter is checking types at run-time. Note that the error messages that it reports contain only "static types". The interpreter is doing both abstract interpretation and concrete interpretation (running) the code at the same time. This allowed us to rapidly evolve the language because the code for the interpretation and the type checking for each construct is woven closely together.

When we introduce the type checking stage, we hope to use the types and the resolved names to get some more speed out of the interpreter, and simplify the interpreter's code again, and of course get the errors to the programmer sooner.

OTHER TIPS

Rascal does have a static type checker, which is written in Rascal itself. It covers most of the language (the only, currently, unsupported feature is keyword parameters). To use it, right click on a Rascal file opened in Eclipse (using the Rascal plugin), select "Experimental", then "Run static checker". As the menu name implies, this is experimental, so please let us know if you find problems.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top