Skip to main content

No Such Field

rascal-0.34.0

Synopsis

Field of an abstract data type value cannot be found at runtime.

Types

data RuntimeException = NoSuchField(str name);

Usage

import Exception; (only needed when NoSuchField is used in catch)

Description

Selecting a field from an abstract datatype depends on the actual constructor being used at run time. This exception is thrown when a non-existent field is accessed.

Examples

Consider this simplified model of lawful entities:

rascal>data Entity = person(str name, int birthYear) | company(str name, Entity director);
ok
rascal>jane = person("Jane", 2001);
Entity: person("Jane",2001)
rascal>icm = company("ICM", jane);
Entity: company(
"ICM",
person("Jane",2001))

The field birthYear is evidently only applicable to a person but not to a company

rascal>icm.birthYear;
|prompt:///|(0,3,<1,0>,<1,3>): NoSuchField("birthYear")
ok
rascal>jane.birthYear;
int: 2001