diff --git a/src/interpreter/runtimeModel.ts b/src/interpreter/runtimeModel.ts index 7b07dba4..640d7c7f 100644 --- a/src/interpreter/runtimeModel.ts +++ b/src/interpreter/runtimeModel.ts @@ -2,7 +2,7 @@ import { WOLLOK_BASE_PACKAGE, WOLLOK_EXTRA_STACK_TRACE_HEADER } from '../constan import { v4 as uuid } from 'uuid' import { getPotentiallyUninitializedLazy } from '../decorators' import { get, is, last, List, match, raise, when } from '../extensions' -import { Assignment, Body, Catch, Describe, Environment, Entity, Expression, Id, If, Literal, LiteralValue, Method, Module, Name, New, Node, Package, Program, Reference, Return, Self, Send, Singleton, Super, Test, Throw, Try, Variable } from '../model' +import { Assignment, Body, Catch, Describe, Environment, Entity, Expression, Id, If, Literal, LiteralValue, Method, Module, Name, New, Node, Package, Program, Reference, Return, Self, Send, Singleton, Super, Test, Throw, Try, Variable, Class } from '../model' import { Interpreter } from './interpreter' const { isArray } = Array @@ -488,6 +488,12 @@ export class Evaluation { const target = node.instantiated.target ?? raise(new Error(`Could not resolve reference to instantiated module ${node.instantiated.name}`)) + const name = node.instantiated.name + + if (!target.is(Class)) raise(new Error(`${name} is not a class, you cannot generate instances of a ${target?.kind}`)) + + if (target.isAbstract) raise(new Error(`${name} is an abstract class, you cannot generate instances`)) + return yield* this.instantiate(target, args) }