Skip to main content

NonVoidTypeRequired

rascal-0.34.0

Synopsis

A type other than void is needed.

Description

This error is generated when a value is needed, so an expression of any type but the void type.

The most prominent examples are splicing for list and set.

Remedy: replace the expression of type void by an expression that computes a value.

Examples

First define a dummy function that returns void:

rascal>void dummy() { return; }
void (): function(|prompt:///|(0,24,<1,0>,<1,24>))
rascal>[1, *dummy(), 2]
|prompt:///|(4,8,<1,4>,<1,12>): Non-void type required
Advice: |https://www.rascal-mpl.org/docs/Rascal/Errors/CompileTimeErrors/NonVoidTypeRequired|
ok
rascal>{1, *dummy(), 2}
|prompt:///|(5,7,<1,5>,<1,12>): Non-void type required
Advice: |https://www.rascal-mpl.org/docs/Rascal/Errors/CompileTimeErrors/NonVoidTypeRequired|
ok

A solution could be to have dummy return a set of a list:

rascal>list[int] dummy() { 
>>>>>>> return [17];
>>>>>>>}
list[int] (): function(|prompt:///|(0,38,<1,0>,<3,1>))
rascal>[1, *dummy(), 2]
list[int]: [1,17,2]
rascal>{1, *dummy(), 2}
set[int]: {1,2,17}