RascalTutor
Synopsis

All errors that can occur during compilation of a Rascal program.

Description
in progress of being adpted to compiler

The following compile time (static) errors can occur in a Rascal program. They cannot be caught by the Rascal program:

1. AmbiguousFunctionReference

Synopsis

An ambiguous function name

Description

Warning: How to generate this error?

Examples
rascal>data D = d(int x);
ok
rascal>data D2 = d(str x);
ok
rascal>d(3).x
int: 3
rascal>d("a").x
str: "a"

2. ArgumentMismatch

Synopsis

The called signature does not match any defined function.

Description

A function has a name and a signature (the names and types of its arguments). This error is reported when a call of a function cannot be associated with a function declaration.

Remedies:

  • Modify the call so that the arguments match the function declaration.

  • Write a new definition for a function with the same name, that matches the argument types in the call.

Examples

Define a function triple that multiplies its argument by 3:

rascal>int triple(int x) = 3 * x;
ok

It works fine:

rascal>triple(5)
int: 15

Unless it is called with an argument of a wrong type:

rascal>triple([1,2,3])
Error: Function of type fun int(int) cannot be called with argument types (list[int]) IN 'triple([1,2,3])'

We can define a new version of triple function that accepts lists:

rascal>list[int] triple(list[int] L) = [3 * x | x <- L];
ok
rascal>triple([1,2,3]);
list[int]: [3,6,9]

3. Arity

Synopsis

The number of arguments of an operator differ from what is required.

Description

Various operators like composition, transitive closure and reflexive transitive closure expect binary relations or tuples as arguments.

Examples

This composition is correct:

rascal>{<1,10>, <2,20>} o {<10,100>, <20, 200>};
rel[int,int]: {
  <1,100>,
  <2,200>
}

This is not, since the first argument has arity 3:

rascal>{<1,5,10>, <2,6,20>} o {<10,100>, <20, 200>};
Error: Relation rel[int, int, int] should have arity of 0 or 2 IN '{<1,5,10>, <2,6,20>}'

These transitive closures are correct:

rascal>{<1,2>, <2,3>,<4,5>}+
rel[int,int]: {
  <2,3>,
  <4,5>,
  <1,3>,
  <1,2>
}
rascal>{<1,2>, <2,3>,<4,5>}*
rel[int,int]: {
  <5,5>,
  <3,3>,
  <1,1>,
  <1,3>,
  <1,2>,
  <2,3>,
  <2,2>,
  <4,5>,
  <4,4>
}

But these are incorrect:

rascal>{<1,2,3>, <2,3,4>,<4,5,6>}+
Error: Invalid type: expected a binary relation over equivalent types, found rel[int, int, int] IN '{<1,2,3>, <2,3,4>,<4,5,6>}'
rascal>{<1,2,3>, <2,3,4>,<4,5,6>}*
Error: Invalid type: expected a binary relation over equivalent types, found rel[int, int, int] IN '{<1,2,3>, <2,3,4>,<4,5,6>}'

4. DateTimeSyntax

Synopsis

A datetime value is syntactically incorrect.

Description

datetime values have a rather complex format as described in datetime. Some errors in the format are treated as syntax errors, others generate the DateTimeSyntax error.

Remedy: Fix the datetime value.

Examples

A correct datetime value:

rascal>$2013-07-15T09:15:23.123+03:00$;
datetime: $2013-07-15T09:15:23.123+03:00$

Certain errors, like a wrong day number (here: 40) lead to a parse error:

rascal>$2013-07-40T09:15:23.123+03:00$;
Parse error

Others, like a wrong month number (here: 15) lead to a DateTimeSyntax error:

rascal>$2010-15-15T09:15:23.123+03:00$;
java.lang.NullPointerException
"EXCEPTION in translateFunctionDeclaration, compiling main: IO(\"Cannot create datetime with provided values.\")"

5. IllegalQualifiedDeclaration

Synopsis

Qualified names cannot be declared.

Description

When the same name is declared in different modules, a qualified name can be used to refer to a specific version of that name. This error is generated when a qualified name is used in a declaration.

Remedy: remove the qualification.

Examples

Using a qualified name gives an error:

rascal>data M::D = d();
An unexpected internal error occurred:
io.usethesource.vallang.exceptions.IllegalIdentifierException: M::D is not a valid identifier
	at io.usethesource.vallang.type.TypeFactory.abstractDataTypeFromTuple(TypeFactory.java:466)
	at io.usethesource.vallang.type.TypeFactory.abstractDataType(TypeFactory.java:459)
	at io.usethesource.vallang.type.AbstractDataType$Info.fromSymbol(AbstractDataType.java:104)
	at io.usethesource.vallang.type.TypeFactory$TypeValues.fromSymbol(TypeFactory.java:908)
	at io.usethesource.vallang.type.ConstructorType$Info.fromSymbol(ConstructorType.java:94)
	at io.usethesource.vallang.type.TypeFactory$TypeValues.fromSymbol(TypeFactory.java:908)
	at io.usethesource.vallang.type.TypeFactory.fromSymbol(TypeFactory.java:637)
	at org.rascalmpl.interpreter.TypeReifier.productionToConstructorType(TypeReifier.java:127)
	at org.rascalmpl.library.experiments.Compiler.RVM.Interpreter.Types.loadProduction(Types.java:28)
	at org.rascalmpl.library.experiments.Compiler.RVM.Interpreter.RVMLinker.loadProduction(RVMLinker.java:127)
	at org.rascalmpl.library.experiments.Compiler.RVM.Interpreter.RVMLinker.declareConstructor(RVMLinker.java:131)
	at org.rascalmpl.library.experiments.Compiler.RVM.Interpreter.RVMLinker.link(RVMLinker.java:421)
	at org.rascalmpl.library.experiments.Compiler.RVM.Interpreter.ExecutionTools.link(ExecutionTools.java:76)
	at org.rascalmpl.library.experiments.Compiler.RVM.Interpreter.repl.CommandExecutor.executeModule(CommandExecutor.java:369)
	at org.rascalmpl.library.experiments.Compiler.RVM.Interpreter.repl.CommandExecutor.evalDeclaration(CommandExecutor.java:675)
	at org.rascalmpl.library.experiments.Compiler.RVM.Interpreter.repl.CommandExecutor.eval(CommandExecutor.java:447)
	at org.rascalmpl.library.experiments.tutor3.TutorCommandExecutor.evalPrint(TutorCommandExecutor.java:75)
	at org.rascalmpl.library.experiments.tutor3.Concept.preprocess(Concept.java:264)
	at org.rascalmpl.library.experiments.tutor3.Onthology.<init>(Onthology.java:131)
	at org.rascalmpl.library.experiments.tutor3.CourseCompiler.compileCourse(CourseCompiler.java:92)
	at org.rascalmpl.library.experiments.tutor3.CourseCompiler.main(CourseCompiler.java:258)

Without the qualification, this is correct:

rascal>data D = d();
ok

6. InvalidDateTimeComparison

Synopsis

Attempt to compare a date with a time.

Description

datetime values may contain two components: date and time. Datetime values that contain both a date and a time can be compared. Dates can also be compared with dates, and times with times. This error is generated when a date is compared with a time.

Examples

Comparing dates with dates:

rascal>$2013-07-15$ < $2014-07-15$
bool: true

Or times with times:

rascal>$T20:03:56.901+01:00$ < $T22:00:56.901+01:00$
bool: true

Or datetimes with datetimes:

rascal>$2013-01-11T23:03:56.901+01:00$ < $2013-01-11T23:05:00.901+01:00$
bool: true

But mixing dates and times gives errors:

rascal>$2013-07-15$ < $T20:03:56.901+01:00$
An unexpected internal error occurred:
java.lang.RuntimeException: java.lang.UnsupportedOperationException: Date and non-Date values are not comparable
	at org.rascalmpl.library.experiments.Compiler.RVM.Interpreter.RVMonJVM.dynRun(RVMonJVM.java:544)
	at org.rascalmpl.library.experiments.Compiler.RVM.Interpreter.RVMonJVM.executeRVMProgram(RVMonJVM.java:235)
	at org.rascalmpl.library.experiments.Compiler.RVM.Interpreter.RVMJVM.executeRVMProgram(RVMJVM.java:137)
	at org.rascalmpl.library.experiments.Compiler.RVM.Interpreter.ExecutionTools.executeProgram(ExecutionTools.java:142)
	at org.rascalmpl.library.experiments.Compiler.RVM.Interpreter.ExecutionTools.executeProgram(ExecutionTools.java:101)
	at org.rascalmpl.library.experiments.Compiler.RVM.Interpreter.repl.CommandExecutor.executeModule(CommandExecutor.java:387)
	at org.rascalmpl.library.experiments.Compiler.RVM.Interpreter.repl.CommandExecutor.evalExpression(CommandExecutor.java:453)
	at org.rascalmpl.library.experiments.Compiler.RVM.Interpreter.repl.CommandExecutor.eval(CommandExecutor.java:438)
	at org.rascalmpl.library.experiments.tutor3.TutorCommandExecutor.evalPrint(TutorCommandExecutor.java:75)
	at org.rascalmpl.library.experiments.tutor3.Concept.preprocess(Concept.java:264)
	at org.rascalmpl.library.experiments.tutor3.Onthology.<init>(Onthology.java:131)
	at org.rascalmpl.library.experiments.tutor3.CourseCompiler.compileCourse(CourseCompiler.java:92)
	at org.rascalmpl.library.experiments.tutor3.CourseCompiler.main(CourseCompiler.java:258)
Caused by: java.lang.UnsupportedOperationException: Date and non-Date values are not comparable
	at io.usethesource.vallang.impl.primitive.DateTimeValues$DateValue.compareTo(DateTimeValues.java:98)
	at io.usethesource.vallang.impl.primitive.DateTimeValues$DateValue.compareTo(DateTimeValues.java:44)
	at org.rascalmpl.library.experiments.Compiler.RVM.Interpreter.RascalPrimitive$274.execute2(RascalPrimitive.java:4488)
	at .ConsoleInput$Compiled.ConsoleInput\main()#0(Unknown Source)
	at org.rascalmpl.library.experiments.Compiler.RVM.Interpreter.RVMonJVM.dynRun(RVMonJVM.java:539)
	... 12 more

7. JavaCompilation

Synopsis

Compilation of generated Java code failed.

Description

Some parts of the Rascal system generate Java code. Most notable is the parser generator. This error message is generated when the compilation of generated Java code fails.

Remedy: Contact the Rascal developers:

Synopsis

Cannot link to a Java method.

Description

Rascal functions can be implemented in Java. This is the case for many functions in the standard library. This requires these elements:

  • An abstract Rascal function declaration (= a function header without a body).

  • The keyword java should be part of the function header.

  • The function declaration is annotated (uing javaClass) with the name of the Java class that implements this function.

This error is generated when the Java implementation cannot be found. Most likely, this is a missing or misspelled Java class name. It is also generated when the function declaration does have a body.

Remedy: Contact the Rascal developers:

If you are an expert developer and have implemented your own extension in Java, please check your own extension code first.

Examples

This is how the size function on lists is declared in the Rascal library:

rascal>@javaClass{org.rascalmpl.library.Prelude}
>>>>>>>public java int size(list[&T] lst);
ok

Misspelling the class name will generate the JavaMethodLink error:

rascal>@javaClass{org.rascalmpl.library.Preludexxx}
>>>>>>>public java int size(list[&T] lst);
ok

The same error message is generated if the function declaration contains a body:

rascal>@javaClass{org.rascalmpl.library.Preludexxx}
>>>>>>>public java int size(list[&T] lst){
>>>>>>>  return 0;
>>>>>>>}
ok

9. MissingModifier

Synopsis

A modifier is missing in a declaration.

Description

Rascal functions can be implemented in Java. This is the case for many functions in the standard library. This requires these elements:

  • An abstract Rascal function declaration (= a function header without a body).

  • The keyword java should be part of the function header.

  • The function declaration is annotated (uing javaClass) with the name of the Java class that implements this function.

This error is generated when the java keyword is missing.

Remedy: Contact the Rascal developers:

If you are an expert developer and have implemented your own extension in Java, please check your own extension code first.

Examples

This is how the size function on lists is declared in the Rascal library:

rascal>@javaClass{org.rascalmpl.library.Prelude}
>>>>>>>public java int size(list[&T] lst);
ok

This is what happens if the java keyword is missing:

rascal>@javaClass{org.rascalmpl.library.Prelude}
>>>>>>>public int size(list[&T] lst);
ok

10. MissingReturn

Synopsis

A return statement is missing from a function body.

Description

Functions return some value (except functions that have return type void). This error is generated when a function body does not return a value.

Remedies:

  • Add a [Rascal:Return] statement to the function body.

  • Rewrite the function so that the function body becomes a single expression and you can use the abbreviated function format, see [$Rascal:Declarations/Function].

Examples

Here is an incorrect definition of function triple:

rascal>int triple(int x) {
>>>>>>>   x * 3;
>>>>>>>}
ok
rascal>triple(5)
int: 15

It should look like this:

rascal>int triple(int x) {
>>>>>>>   return x * 3;
>>>>>>>}
ok
rascal>triple(5)
int: 15

This is another solution using the abbreviated function format:

rascal>int triple(int x) = x * 3;
ok
rascal>triple(5)
int: 15

11. ModuleImport

Synopsis

A Rascal module could not be imported.

Description

Rascal programs are split up in modules. An import statement is used to include one module in another. This error indicates that a module import failed. This can be caused by

  • A misspelled name in the import statement.

  • Starting a Rascal console from the wrong directory.

Remedies:

  • Correct the mispelled name.

  • In Eclipse the safest way to execute a Rascal module is to select it in the Package Explorer, right click on it and then select Run as Rascal Application.

  • At the command line, change directory to where the toplevel module of your program is located and then execute the Rascal Shell.

Examples

Here is a correct import of the library module List:

rascal>import List;
ok

Here is the effect of a misspelled module name (assuming that you do not have a module Lis):

rascal>import Lis;
Error: Cannot import module Lis

12. ModuleNameMismatch

Synopsis

Module name and file name are different.

Description

A Rascal module has a name (the name that follows the module keyword) and it is stored in a file. The (enforced) convention is that the name of the module (say MyModule) and the name of the file should be the same (except fo the Rascal extension .rsc). Module MyModule should be stored in the file MyModule.rsc. This error signals that this convention is violated.

Remedies:

  • Rename the module.

  • Rename the file.

13. NoKeywordParameters

Synopsis

A function that is declared without keyword parameters is called with keyword parameters.

Description

Functions maybe declared with or without keyword parameters. This error is generated when a function has been declared without keyword parameters but is called with a keyword parameter.

Remedies:

  • Replace the keyword parameter in the call by a positional parameter.

  • Add a keyword parameter to the function declaration.

Examples
rascal>int incr(int x) = x + 1;
ok
rascal>incr(3, delta=5);
Error: Unknown keyword parameter passed: delta IN 'incr(3, delta=5)'

Here is one solution:

rascal>int incr(int x, int delta=1) = x + delta;
ok
rascal>incr(3, delta=5);
int: 8

14. NonAbstractJavaFunction

Synopsis

A function declared with the java modifier has a Rascal body.

Description

Rascal functions can be implemented in Java. This is the case for many functions in the standard library. This requires these elements:

  • An abstract Rascal function declaration (= a function header without a body).

  • The keyword java should be part of the function header.

  • The function declaration is annotated (uing javaClass) with the name of the Java class that implements this function.

This error is generated when the function does have a body.

Remedies:

If you are an expert developer, please check the body of the offending function first.

Examples
rascal>java int incr(int x) {}
ok

15. NonVoidTypeRequired

Synopsis

A type other than void is needed.

Description

This error is generated when a non-void value is needed, but only void is provided. The most prominent examples are splicing for list, set, and map.

Remedy: replace the expression that computes void by an expression that computes a non-void value.

Examples

First define a dummy function that returns void:

rascal>void dummy() { return; }
ok
rascal>[1, *dummy(), 2]
list[int]: [1,666,2]
rascal>{1, *dummy(), 2}
set[int]: {2,1,666}

A solution could be:

rascal>int dummy() { return 17; }
ok
rascal>[1, *dummy(), 2]
list[int]: [1,17,2]
rascal>{1, *dummy(), 2}
set[int]: {1,2,17}

16. NonWellformedType

Synopsis

A type in a declaration is not wellformed.

Description

Types should respect some structural rules and this error signals a violation of these rules. Examples of violations are:

  • a non-parametric type has parameters.

  • a parametric type has an incorrect number of parameters.

Remedy: correct the type.

Examples
rascal>bool[int] x;
Error: Type bool does not accept type parameters IN 'bool[int]'
rascal>list[int,str] l;
Error: Non-well-formed type, type should have one type argument IN 'list[int,str]'
rascal>map[str, int, int]  m;
Error: Non-well-formed type, type should have two type argument IN 'map[str, int, int]'
rascal>set[int,str] s;
Error: Non-well-formed type, type should have one type argument IN 'set[int,str]'

17. NotEnumerable

Synopsis

A value that cannot be enumerated is used in an enumerator.

Description

An enumerator like int n ← V is used in comprehensions to enumerate the values in V. This error is produced when V is a value that does not support enumeration. This is typically the case for atomic values like numbers, Booleans and Strings,

Remedy: modify the expression in the enumerator to return a value that supports enumeration.

Examples
rascal>int x <- 17
Error: Type int is not enumerable IN 'int x <- 17'
rascal>b <- true
Error: Type bool is not enumerable IN 'b <- true'

18. PartiallyLabeledFields

Synopsis

In a tuple or relation all fields should have names or none at all.

Description

The fields in tuples and relations can optionally be labelled with a name. There are only two legal situations:

  • All fields have a label.

  • No field has a label.

This error signals the case that thei fields are partially labelled.

Examples
rascal>tuple[int n, str] T;
ok
rascal>rel[str name, int] R;
ok

19. RedeclaredField

Synopsis

A field name is redeclared.

Description

The definition of an algebraic data type consists of a number of constructor functions. Each constructor has named fields but the same field name may only be used in different constructors if it has the same type in all occurrences in the declaration.

Remedy: rename one of the fields in the declaration.

Examples

This is correct since all occurrences of key have type int:

rascal>data D = d1(int key) | d2(str name, int key);
ok

This is incorrect since key is used as int and as str.

rascal>data D = d1(int key) | d2(str key);
Error: Field key already defined as type int on datatype D, cannot redefine to type str IN 'd2(str key)'

This can be corrected by choosing other names for the labels:

rascal>data D = d1(int intKey) | d2(str strKey);
ok

A tuple declaration with a duplicate field name also gives an error:

rascal>tuple[int x, str x] Q = <3,"abc">;
Error: Non-well-formed type, labels must be distinct IN 'tuple[int x, str x]'

20. RedeclaredType

Synopsis

A type with the same name has been declared before.

Description

Some declarations introduce new type names. Most important are an algebraic data type and alias. This error signals that the same type name is used for incompatible purposes.

Remedy: rename one of the type names.

Examples
rascal>data D = d(int x);
ok
rascal>alias D = str;
Error: Not supported construct: alias D = str;
rascal>alias D = int;
Error: Not supported construct: alias D = int;
rascal>alias D = str;
Error: Not supported construct: alias D = str;

21. RedeclaredVariable

Synopsis

A variable with the same name has been declared in the same scope.

Description

Remedy: rename one of the variables.

Examples
rascal>int n = 3;
int: 3
rascal>int n = 4;
int: 4

22. SyntaxError

Synopsis

Text in a module or entered via the command line violates the Rascal syntax.

Description

This error is generated when a text is expected to be Rascal but does not comply with the Rascal syntax.

Remedy: Correct your text and check for the following:

  • All parentheses are balanced: (…​), […​], {…​}, <…​>, /…​/.

  • All multi-line comments are balanced: /…​/.

  • All semi-colons are present.

  • All tests in if, for, while statement are surrounded by (…​).

When you are completely desparate and cannot find the syntax error, the following binary search strategy may help:

  • Surround all text in the module (except the module header) with / and /. Now your module should parse. If not the syntax error is in the module header.

  • Move the upper comment symbol /* to the middle of the file. Now there are two possibilities:

    • The module parses. The top part is correct and the syntax error is in the bottom part. Move the /* marker to the middle of the bottom part and repeat.

    • The module does not parse. The syntax error is in the top part. Move the /* marker to the middle of the top part and repeat.

23. UndeclaredAnnotation

Synopsis

An annotation is used that has not been declared.

Description

An annotation can be used to add information to an instance of an algebraic data type. An annotation has to declared beforehand. This error is generated when an undeclared annotation is used.

Remedies:

  • Declare the annotation.

  • Use an already declared annotation.

Examples

This is correct:

rascal>data Fruit = apple(int n) | orange(int n);
ok
rascal>anno str Fruit @ quality;
Error: Not supported construct: anno str Fruit @ quality;
rascal>piece = orange(13);
Fruit: orange(13)
rascal>piece @ quality = "great";
str: "great"

But using a wrong annotation name generates an error:

rascal>piece @ qual;
Parse error

24. UndeclaredField

Synopsis

A field name is used that has not been declared.

Description

Fields of tuple (hence also of relation and listrelation) and constructors of algebraic data types may have names. This error is generated when a reference is made to an undeclared field.

Remedies:

  • Fix the field name in the reference.

  • Declare a new field as used in the reference.

Examples

Use of the undeclared field gender:

rascal>tuple[str name, int age] Jo = <"Jo", 33>;
tuple[str,int]: <"Jo",33>
rascal>Jo.gender;
Error: Field gender does not exist on type tuple[str name, int age] IN 'Jo.gender'

A similar example now expressed as ADT:

rascal>data Person = person(str name, int age);
ok
rascal>jo = person("Jo", 33);
Person: person("Jo",33)
rascal>jo.gender;
Error: Field gender does not exist on type Person IN 'jo.gender'

25. UndeclaredFunction

Synopsis

A function is called that has not been declared.

Description

All functions, constructors and variables have to be declared before they can be used. This error is generated when this rule is violated.

Remedies for functions:

  • Declare the function.

  • Declare the function as constructor of an (existing or new) [Rascal:AlgebraicDataType].

  • Import a module that declares the function (Did you import all necessary library modules?)

Remedies for variables:

  • Declare the variable.

Examples

Calling the undeclared function triple gives an error:

rascal>triple(5)
Error: Name triple is not in scope

We can remedy this by declaring the function:

rascal>int triple(int n) = 3 * n;
ok
rascal>triple(5)
int: 15

Calling the library function size gives an error if the proper library (in this case: List) is not imported

rascal>size([20, 1, 77]);
Error: Name size is not in scope

The solution is:

rascal>import List;
ok
rascal>size([20, 1, 77]);
int: 3

Another solution is to import the complete Rascal library at once:

rascal>import Prelude;
ok
rascal>size([20, 1, 77]);
int: 3

Using an undeclared variable gives an error:

rascal>n + 1;
Error: Name n is not in scope

A variable is introduced by just assigning to it (with or without its expected type):

rascal>n = 3;
int: 3
rascal>n + 1;
int: 4

Or equivalenty (with an expected type):

rascal>int n = 3;
int: 3
rascal>n + 1;
int: 4

26. UndeclaredJavaMethod

Synopsis

Attempt to call a non-existing Java method.

Description

Rascal functions can be implemented in Java. This is the case for many functions in the standard library. This requires these elements:

  • An abstract Rascal function declaration (= a function header without a body).

  • The keyword java should be part of the function header.

  • The function declaration is annotated (uing javaClass) with the name of the Java class that implements this function.

This error is generated when a method with the same name as the Rascal function cannot be found in the mentioned Java class. Most likely, this is a missing or misspelled function/method name.

Remedy: Contact the Rascal developers:

If you are an expert developer and have implemented your own extension in Java, please check your own extension code first.

Examples

This is how the size function on lists is declared in the Rascal library:

rascal>@javaClass{org.rascalmpl.library.Prelude}
>>>>>>>public java int size(list[&T] lst);
ok

This is the result of misspelling the function name (siz instead of size):

rascal>@javaClass{org.rascalmpl.library.Prelude}
>>>>>>>public java int siz(list[&T] lst);
ok

27. UndeclaredKeywordParameter

Synopsis

A function is called with a keyword parameter that was not declared in the function’s declaration.

Description

Rascal functions may have keyword parameters. This error is generated when a function call uses an undeclared keyword parameter.

Remedies:

  • Rename the keyword parameter in the call.

  • Add a new keyword parameter to the function.

Examples
rascal>int incr(int n, int delta=1) = n + delta;
ok

Calling incr with a wrong keyword parameter gives an error:

rascal>incr(3, diff=5);
Error: Unknown keyword parameter passed: diff IN 'incr(3, diff=5)'

This can be fixed by using the correct name for the keyword parameter:

rascal>incr(3, delta=5);
int: 8

28. UndeclaredModule

Synopsis

Reference to a non-existing module.

Description

This can, for example, occur in a qualified name.

Remedies:

  • Check that the offending module name is spelled correctly.

  • Create a module of that name.

Examples

Referring to the non-existing module M gives errors:

rascal>M::x = 3;
int: 3
rascal>M::f(3);
An unexpected internal error occurred:
java.lang.RuntimeException: Parse error
at test-modules:///ConsoleInput.rsc offset=25 length=1 begin=1:5 end=1:6
	at org.rascalmpl.library.experiments.Compiler.RVM.Interpreter.RVMonJVM.executeRVMFunction(RVMonJVM.java:182)
	at org.rascalmpl.library.experiments.Compiler.RVM.Interpreter.RVMJVM.executeRVMFunction(RVMJVM.java:127)
	at org.rascalmpl.library.experiments.Compiler.RVM.Interpreter.RVMCore.executeRVMFunction(RVMCore.java:449)
	at org.rascalmpl.library.experiments.Compiler.RVM.Interpreter.java2rascal.RascalFunctionInvocationHandler.invoke(RascalFunctionInvocationHandler.java:85)
	at com.sun.proxy.$Proxy2.compileAndMergeProgramIncremental(Unknown Source)
	at org.rascalmpl.library.experiments.Compiler.RVM.Interpreter.repl.CommandExecutor.executeModule(CommandExecutor.java:361)
	at org.rascalmpl.library.experiments.Compiler.RVM.Interpreter.repl.CommandExecutor.evalStatement(CommandExecutor.java:520)
	at org.rascalmpl.library.experiments.Compiler.RVM.Interpreter.repl.CommandExecutor.eval(CommandExecutor.java:441)
	at org.rascalmpl.library.experiments.tutor3.TutorCommandExecutor.evalPrint(TutorCommandExecutor.java:75)
	at org.rascalmpl.library.experiments.tutor3.Concept.preprocess(Concept.java:264)
	at org.rascalmpl.library.experiments.tutor3.Onthology.<init>(Onthology.java:131)
	at org.rascalmpl.library.experiments.tutor3.CourseCompiler.compileCourse(CourseCompiler.java:92)
	at org.rascalmpl.library.experiments.tutor3.CourseCompiler.main(CourseCompiler.java:258)
Caused by: Parse error
at test-modules:///ConsoleInput.rsc offset=25 length=1 begin=1:5 end=1:6
	at org.rascalmpl.parser.gtd.SGTDBF.parse(SGTDBF.java:1198)
	at org.rascalmpl.parser.gtd.SGTDBF.parse(SGTDBF.java:1236)
	at org.rascalmpl.parser.gtd.SGTDBF.parse(SGTDBF.java:1241)
	at org.rascalmpl.parser.gtd.SGTDBF.parse(SGTDBF.java:1253)
	at org.rascalmpl.library.util.ReflectiveCompiled.parseModuleWithSpaces(ReflectiveCompiled.java:72)
	at org.rascalmpl.library.util.Reflective.parseModule(Reflective.java:290)
	at sun.reflect.GeneratedMethodAccessor114.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.rascalmpl.library.experiments.Compiler.RVM.Interpreter.RVMCore.callJavaMethod(RVMCore.java:1114)
	at org.rascalmpl.library.experiments.Compiler.RVM.Interpreter.RVMonJVM.insnCALLJAVA(RVMonJVM.java:403)
	at lang.rascal.boot.Kernel$Compiled.util::Reflective\parseModule(\loc():)#51(Unknown Source)
	at lang.rascal.boot.Kernel$Compiled.experiments::Compiler::Compile\compile1Incremental(str():bool():adt("PathConfig",()):)#319(Unknown Source)
	at lang.rascal.boot.Kernel$Compiled.experiments::Compiler::Compile\compileIncremental(str():bool():adt("PathConfig",()):)#383(Unknown Source)
	at lang.rascal.boot.Kernel$Compiled.experiments::Compiler::Execute\compileAndMergeProgramIncremental(str():bool():adt("PathConfig",()):)#552(Unknown Source)
	at org.rascalmpl.library.experiments.Compiler.RVM.Interpreter.RVMonJVM.executeRVMFunction(RVMonJVM.java:176)
	... 12 more

29. UndeclaredModuleProvider

Synopsis

A scheme is used in a location for wich no provider has been registered.

Description

Locations provide very flexible ways to access files and external data sources. There any many protocols (called schemes) that can be used (e.g., file, http, home and many others). This error is generated when an unknown scheme is used.

Remedy: Use an existing scheme.

Examples

Misspelling the scheme for Rascal’s standard library (which is std) gives an error when the location is used:

rascal>import IO;
ok
rascal>readFileLines(|standard:///demo/basic/Hello.rsc|);
Exception [debugger cannot break at null frame]: IO("Unsupported scheme standard")

This is fixed by using the proper scheme name:

rascal>readFileLines(|std:///demo/basic/Hello.rsc|);
list[str]: ["@license{","  Copyright (c) 2009-2015 CWI","  All rights reserved. This program and the accompanying materials","  are made available under the terms of the Eclipse Public License v1.0","  which accompanies this distribution, and is available at","  http://www.eclipse.org/legal/epl-v10.html","}","@contributor{Jurgen J. Vinju - Jurgen.Vinju@cwi.nl - CWI}","@contributor{Paul Klint - Paul.Klint@cwi.nl - CWI}","//START","// tag::module[]","module demo::basic::Hello","","import IO;","","void hello() {","   println(\"Hello world, this is my first Rascal program\");","}","// end::module[]"]

30. UndeclaredNonTerminal

Synopsis

A syntax rule uses an undeclared non-terminal.

Description

All non-terminals that occur in a syntax definition should be declared in some rule. This error is generated when this is not the case.

Remedy: declare the offending non-terminal.

Examples

Here is an example where the non-terminal Y is not declared:

rascal>import ParseTree;
ok
rascal>syntax X = "a" Y;
Error: Syntax type Y is not defined IN 'syntax X = "a" Y;'
Error: Nonterminal Y not declared
rascal>parse(#X, "ab");
Error: Could not instantiate type variables in type fun &T <: Tree(type[&T <: Tree], str) with argument types (type[fail],str) IN 'parse(#X, "ab")'
Error: Function of type fun &T <: Tree(type[&T <: Tree], str, loc) cannot be called with argument types (type[fail],str) IN 'parse(#X, "ab")'
Error: Could not instantiate type variables in type fun &T <: Tree(type[&T <: Tree], loc) with argument types (type[fail],str) IN 'parse(#X, "ab")'
Pitfalls

The source location of the non-terminal is not yet available, so the error message mentions the module in which this occurs.

31. UndeclaredType

Synopsis

Use of a type that has not been declared.

Description

A type has to be declared before it can be used. This error is generated when an undeclared type is used.

Remedies:

  • Rename the type name.

  • Declare the type.

  • Import a module that declares the type. (Did you import all library modules?)

Examples

Using the undeclared type myint gives an error:

rascal>myint incr(myint n) = n + 1;
Error: Could not calculate function type because of errors calculating the parameter types IN 'myint incr(myint n)'
Error: Type of pattern could not be computed IN 'myint n'
Error: Type myint not declared

The solkution is to first declares myint (here as an alias for int):

rascal>alias myint = int;
Error: Not supported construct: alias myint = int;
rascal>myint incr(myint n) = n + 1;
Error: Could not calculate function type because of errors calculating the parameter types IN 'myint incr(myint n)'
Error: Type of pattern could not be computed IN 'myint n'
Error: Type myint not declared
rascal>incr(3);
Error: Name incr is not in scope

32. UndeclaredVariable

Synopsis

Use of a variable that has not been declared.

Description

A variable can only be used when it has been declared and initialized. This error is generated when this is not the case.

Remedy:

  • Rename the offending variable name into the name of an existing variable.

  • Introduce a new variable.

Examples

Here is an example where an undeclared variables occurs in list splicing:

rascal>[1, *x, 3]
Error: Name x is not in scope

The remedy is here:

rascal>x = 5;
int: 5
rascal>[1, *x, 3]
list[int]: [1,5,3]

33. UnexpectedKeywordArgumentType

Synopsis

The actual value of a keyword argument is not compatible with its declared type.

Description

Functions may be declared to have keyword parameters. Each keyword parameters has a type, a name and a default value. This error is generated when the declared type and the actual type of the keyword parameter are not compatible.

Remedies:

  • Change the type of the keyword parameter in the call.

  • Change the type of the keyword parameter in the function declaration.

Examples

Declare incr function with keyword parameter delta of type int:

rascal>int incr(int x, int delta = 1) = n + delta;
Error: Name n is not in scope

Erroneous use of delta with a string value:

rascal>incr(3, delta="more");
Error: Name incr is not in scope

34. UnexpectedType

Synopsis

A value of a different type was expected.

Description

This error signals an incompatibility between expected type and actual type. Some of the situations in which this may occur are assert, variable, solve.

Remedy: adjust the actual type to the expected type.

Examples

Declaring variable n as int and assigning it a str value gives an error:

rascal>int n = "abc";
Error: Unable to bind subject type str to assignable IN 'n = "abc";'

The solution is to assign an int value to n:

rascal>int n = 123;
int: 123

An assert statement expects an argument of type bool:

rascal>assert 3;
Error: Invalid type int, expected expression of type bool

35. UnguardedAppend

Synopsis

Append statement occurs outside a for/while statement.

Description

The append statement can be used inside a loop statement. This error is generated when append occurs outside a loop.

Remedy: use List concatenation to append an element to a list outside a loop.

Examples

This is the typical use of append:

rascal>for(int i <- [1..5]) append i*i;
list[int]: [1,4,9,16]

Using append outside a loop gives an error:

rascal>append 3;
An unexpected internal error occurred:
java.lang.RuntimeException: Parse error
at test-modules:///ConsoleInput.rsc offset=58 length=1 begin=2:37 end=2:38
	at org.rascalmpl.library.experiments.Compiler.RVM.Interpreter.RVMonJVM.executeRVMFunction(RVMonJVM.java:182)
	at org.rascalmpl.library.experiments.Compiler.RVM.Interpreter.RVMJVM.executeRVMFunction(RVMJVM.java:127)
	at org.rascalmpl.library.experiments.Compiler.RVM.Interpreter.RVMCore.executeRVMFunction(RVMCore.java:449)
	at org.rascalmpl.library.experiments.Compiler.RVM.Interpreter.java2rascal.RascalFunctionInvocationHandler.invoke(RascalFunctionInvocationHandler.java:85)
	at com.sun.proxy.$Proxy2.compileAndMergeProgramIncremental(Unknown Source)
	at org.rascalmpl.library.experiments.Compiler.RVM.Interpreter.repl.CommandExecutor.executeModule(CommandExecutor.java:361)
	at org.rascalmpl.library.experiments.Compiler.RVM.Interpreter.repl.CommandExecutor.evalStatement(CommandExecutor.java:622)
	at org.rascalmpl.library.experiments.Compiler.RVM.Interpreter.repl.CommandExecutor.eval(CommandExecutor.java:441)
	at org.rascalmpl.library.experiments.tutor3.TutorCommandExecutor.evalPrint(TutorCommandExecutor.java:75)
	at org.rascalmpl.library.experiments.tutor3.Concept.preprocess(Concept.java:264)
	at org.rascalmpl.library.experiments.tutor3.Onthology.<init>(Onthology.java:131)
	at org.rascalmpl.library.experiments.tutor3.CourseCompiler.compileCourse(CourseCompiler.java:92)
	at org.rascalmpl.library.experiments.tutor3.CourseCompiler.main(CourseCompiler.java:258)
Caused by: Parse error
at test-modules:///ConsoleInput.rsc offset=58 length=1 begin=2:37 end=2:38
	at org.rascalmpl.parser.gtd.SGTDBF.parse(SGTDBF.java:1198)
	at org.rascalmpl.parser.gtd.SGTDBF.parse(SGTDBF.java:1236)
	at org.rascalmpl.parser.gtd.SGTDBF.parse(SGTDBF.java:1241)
	at org.rascalmpl.parser.gtd.SGTDBF.parse(SGTDBF.java:1253)
	at org.rascalmpl.library.util.ReflectiveCompiled.parseModuleWithSpaces(ReflectiveCompiled.java:72)
	at org.rascalmpl.library.util.Reflective.parseModule(Reflective.java:290)
	at sun.reflect.GeneratedMethodAccessor114.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.rascalmpl.library.experiments.Compiler.RVM.Interpreter.RVMCore.callJavaMethod(RVMCore.java:1114)
	at org.rascalmpl.library.experiments.Compiler.RVM.Interpreter.RVMonJVM.insnCALLJAVA(RVMonJVM.java:403)
	at lang.rascal.boot.Kernel$Compiled.util::Reflective\parseModule(\loc():)#51(Unknown Source)
	at lang.rascal.boot.Kernel$Compiled.experiments::Compiler::Compile\compile1Incremental(str():bool():adt("PathConfig",()):)#319(Unknown Source)
	at lang.rascal.boot.Kernel$Compiled.experiments::Compiler::Compile\compileIncremental(str():bool():adt("PathConfig",()):)#383(Unknown Source)
	at lang.rascal.boot.Kernel$Compiled.experiments::Compiler::Execute\compileAndMergeProgramIncremental(str():bool():adt("PathConfig",()):)#552(Unknown Source)
	at org.rascalmpl.library.experiments.Compiler.RVM.Interpreter.RVMonJVM.executeRVMFunction(RVMonJVM.java:176)
	... 12 more

36. UnguardedFail

Synopsis

Use of fail statement outside a condtional context.

Description

A fail statement is only allowed inside conditional statements. This error is generated when fail is used outside a conditional context.

Remedies:

  • Surround the fail statement by a conditional conditional statement.

  • Replace the fail statement by a [Rascal:Throw] statement.

  • replace the fail statement by a [Rascal:Return] statement.

Examples

Here is a correct (albeit not very useful) use of fail where the pattern match int N := 35 acts as guard:

rascal>if(int N := 35){ if(N > 10) fail; }
int: 666

Any condition (non only one using pattern matching) can act as guard:

rascal>if(true) { fail; }
int: 666

An error occurs when fail is used outside a conditional context:

rascal>fail;
ok

37. UnguardedInsert

Synopsis

An insert occurs outside a visit expression.

Description

An insert statement may only occur in the action part of a pattern with action, more precisely in a case in a visit expression.

Remedies:

  • Use an auxiliary variable and list or set operations to insert the value where you want.

  • Place the insert statement inside a visit.

Examples

Here is an example of the use of insert to swap the arguments of red nodes:

Our favorite data type, colored trees:

rascal>data CTree = leaf(int n) | red(CTree left, CTree right) | green(CTree left, CTree right);
ok

An example tree:

rascal>CTree T = red(green(leaf(1), red(leaf(2), leaf(3))), red(leaf(4), leaf(5)));
CTree: red(
  green(
    leaf(1),
    red(
      leaf(2),
      leaf(3))),
  red(
    leaf(4),
    leaf(5)))

A visit to swap the arguments of red nodes:

rascal>visit(T){ case red(CTree l, CTree r): insert red(r,l); }
CTree: red(
  red(
    leaf(5),
    leaf(4)),
  green(
    leaf(1),
    red(
      leaf(3),
      leaf(2))))

An error occurs when insert is used outside a visit:

rascal>insert red(leaf(1), leaf(2));
An unexpected internal error occurred:
java.lang.RuntimeException: Parse error
at test-modules:///ConsoleInput.rsc offset=178 length=1 begin=5:57 end=5:58
	at org.rascalmpl.library.experiments.Compiler.RVM.Interpreter.RVMonJVM.executeRVMFunction(RVMonJVM.java:182)
	at org.rascalmpl.library.experiments.Compiler.RVM.Interpreter.RVMJVM.executeRVMFunction(RVMJVM.java:127)
	at org.rascalmpl.library.experiments.Compiler.RVM.Interpreter.RVMCore.executeRVMFunction(RVMCore.java:449)
	at org.rascalmpl.library.experiments.Compiler.RVM.Interpreter.java2rascal.RascalFunctionInvocationHandler.invoke(RascalFunctionInvocationHandler.java:85)
	at com.sun.proxy.$Proxy2.compileAndMergeProgramIncremental(Unknown Source)
	at org.rascalmpl.library.experiments.Compiler.RVM.Interpreter.repl.CommandExecutor.executeModule(CommandExecutor.java:361)
	at org.rascalmpl.library.experiments.Compiler.RVM.Interpreter.repl.CommandExecutor.evalStatement(CommandExecutor.java:622)
	at org.rascalmpl.library.experiments.Compiler.RVM.Interpreter.repl.CommandExecutor.eval(CommandExecutor.java:441)
	at org.rascalmpl.library.experiments.tutor3.TutorCommandExecutor.evalPrint(TutorCommandExecutor.java:75)
	at org.rascalmpl.library.experiments.tutor3.Concept.preprocess(Concept.java:264)
	at org.rascalmpl.library.experiments.tutor3.Onthology.<init>(Onthology.java:131)
	at org.rascalmpl.library.experiments.tutor3.CourseCompiler.compileCourse(CourseCompiler.java:92)
	at org.rascalmpl.library.experiments.tutor3.CourseCompiler.main(CourseCompiler.java:258)
Caused by: Parse error
at test-modules:///ConsoleInput.rsc offset=178 length=1 begin=5:57 end=5:58
	at org.rascalmpl.parser.gtd.SGTDBF.parse(SGTDBF.java:1198)
	at org.rascalmpl.parser.gtd.SGTDBF.parse(SGTDBF.java:1236)
	at org.rascalmpl.parser.gtd.SGTDBF.parse(SGTDBF.java:1241)
	at org.rascalmpl.parser.gtd.SGTDBF.parse(SGTDBF.java:1253)
	at org.rascalmpl.library.util.ReflectiveCompiled.parseModuleWithSpaces(ReflectiveCompiled.java:72)
	at org.rascalmpl.library.util.Reflective.parseModule(Reflective.java:290)
	at sun.reflect.GeneratedMethodAccessor114.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.rascalmpl.library.experiments.Compiler.RVM.Interpreter.RVMCore.callJavaMethod(RVMCore.java:1114)
	at org.rascalmpl.library.experiments.Compiler.RVM.Interpreter.RVMonJVM.insnCALLJAVA(RVMonJVM.java:403)
	at lang.rascal.boot.Kernel$Compiled.util::Reflective\parseModule(\loc():)#51(Unknown Source)
	at lang.rascal.boot.Kernel$Compiled.experiments::Compiler::Compile\compile1Incremental(str():bool():adt("PathConfig",()):)#319(Unknown Source)
	at lang.rascal.boot.Kernel$Compiled.experiments::Compiler::Compile\compileIncremental(str():bool():adt("PathConfig",()):)#383(Unknown Source)
	at lang.rascal.boot.Kernel$Compiled.experiments::Compiler::Execute\compileAndMergeProgramIncremental(str():bool():adt("PathConfig",()):)#552(Unknown Source)
	at org.rascalmpl.library.experiments.Compiler.RVM.Interpreter.RVMonJVM.executeRVMFunction(RVMonJVM.java:176)
	... 12 more

38. UnguardedIt

Synopsis

The special variable it occurs outside a reducer expression.

Description

A reducer is used to reduce all elements in a collection to a sngle value. The special variable it represents the currently reduced value and can be modified inside the reducer. This error is generated when it i used otuside the a reducer.

Remedies:

  • You have accidentially used a variable with the name it; rename your variable to something else.

  • Place the expression that contains it in a reducer expression.

Examples

This is correct way to add all elements in a list:

rascal>(0 | it + n | int n <- [1,5,9] )
int: 15

Using it outside a reducer gives an error:

rascal>it + 3
Error: Name it not in scope

39. UnguardedReturn

Synopsis

A return statement occurs outside a function body.

Description

A return statement is used to return a value from a function. It is an error to use it outside a function body.

Examples
rascal>int triple(int n) { return 3 * n; }
ok
rascal>triple(5);
int: 15

Using return outside a function body gives an error:

rascal>return 3;
int: 3

40. UninitializedPatternMatch

Synopsis

Pattern matching has not been properly initialized.

Description

Pattern matching requires two ingredients:

  • One of the many patterns.

  • A non-void subject value to which the pattern is applied.

This error is generated when the subject is void.

Remedy: replace the subject by a non-void value.

Examples

here is a (contrived) example that produces this error:

rascal>void dummy() { return; }
ok
rascal>int n := dummy();
bool: true

41. UnitializedVariable

Synopsis

Use of a variable that has not been initialized.

Description

A variable has to be initialized before it can be used. This error is generated when an uninitialzed variable is used.

Remedy: assign a value to the variable before its use:

Examples

Using the uninitialized variable x gives an error:

rascal>x + 5;
Error: Name x is not in scope

This can be avoided by first initializing x:

rascal>x = 3;
int: 3
rascal>x + 5;
int: 8

42. UnsupportedOperation

Synopsis

Attempt to apply a operation to a value for which the operation is not defined.

Description

This error is generated when an unsupported operation is applied to (a combination of) values. There can be many causes for this as illustrated below.

Remedies:

  • Change the operation to another operations that is supported on the given values.

  • Change the values so that the operation can be applied to them.

  • Rewrite the expression compleye to get the effect you intended.

Examples
rascal>L = [1,2,3];
list[int]: [1,2,3]

Division is not supported on lists:

rascal>[1, 2, 3] / 4;
Error: Division not defined on list[int] and int IN '[1, 2, 3] / 4'

Combined multiplication and assignment is not supported either:

rascal>L *= 3;
Error: Product not defined on list[int] and int IN 'L *= 3;'

Taking the time from a date-only value is not supported:

rascal>$2010-07-15$.justTime;
Exception [debugger cannot break at null frame]: UnavailableInformation("Can not retrieve the time component of a date value")

Calling an integer as a function is not supported:

rascal>17(3, "abc");
Error: Cannot use type int in calls IN '17(3, "abc")'

43. UnsupportedPattern

Synopsis

A pattern is used that is not supported.

Description

This is a case where the syntax (parser) of Rascal allows some kind of pattern, while the semantics (interpreter) does not support it (yet). To solve this issue, usually you can introduce a variable in the place of the not support pattern, and check conditions on the value "manually" later.

Examples

Warning: To Do

44. UnsupportedSubscript

Synopsis

A subscript is applied to a value that does not support it.

Description

Subscription is available for values of various types including: string, node, list, map, tuple and relation. This error is generated when subscription is applied to a value for which it is not defined.

Remedies:

  • Use another operation than subscription to extract the values you want.

  • Use another type (that does support subscription) to represent your data.

Examples

Here are some correct uses of subscription:

rascal>"abc"[1];
str: "b"
rascal>[1,2,3][1];
int: 2
rascal>"f"(1,2,3)[1];
int: 2
rascal>("a":1, "b":2, "c":3)["b"]
int: 2

Here are some erroneous examples:

rascal>true[1];
Error: Expressions of type bool cannot be subscripted IN 'true[1]'
rascal>123[1];
Error: Expressions of type int cannot be subscripted IN '123[1]'
rascal>{1,2,3}[1];
Error: Expressions of type set[int] cannot be subscripted IN '{1,2,3}[1]'

45. UnsupportedSubscriptArity

Synopsis

Wrong number of subscripts is used.

Description

Subscription is available for values of various types including: string, node, list, map, tuple and relation. This error is generated when subscription is applied to a value that does support subscription but not the number of indices that are used.

Remedies: correct the number of indices used in the subscription.

Examples
rascal>[1,2,3][2,1];
Error: Expected only 1 subscript for a list expression, not 2 IN '[1,2,3][2,1]'
rascal>("a":1, "b":2, "c":3)["c", "d"];
Error: Expected only 1 subscript for a map expression, not 2 IN '("a":1, "b":2, "c":3)["c", "d"]'
rascal><1, 2, 3>[5,6];
Error: Expected only 1 subscript for a tuple expression, not 2 IN '<1, 2, 3>[5,6]'