Skip to content

Commit

Permalink
feat: error if call receiver is class without constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
lars-reimann committed Oct 12, 2023
1 parent 128b98d commit 23d960f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/language/validation/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getContainerOfType, ValidationAcceptor } from 'langium';
import {
isSdsAnnotation,
isSdsCallable,
isSdsCallable, isSdsClass,
isSdsLambda, isSdsMemberAccess, isSdsPipeline, isSdsReference, isSdsSchema,
SdsAttribute,
SdsCall,
Expand Down Expand Up @@ -46,6 +46,11 @@ export const callReceiverMustBeCallable = (services: SafeDsServices) => {
node: node.receiver,
code: CODE_TYPE_CALLABLE_RECEIVER,
});
} else if (isSdsClass(callable) && !callable.parameterList) {
accept('error', "Cannot instantiate a class that has no constructor.", {
node: node.receiver,
code: CODE_TYPE_CALLABLE_RECEIVER,
});
}
};
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package tests.validation.types.checking.calledClassMustHaveConstructor

class A

class B()

pipeline test {

// $TEST$ error "Cannot instantiate a class that has no constructor."
val a = »A«();

// $TEST$ no error "Cannot instantiate a class that has no constructor."
val b = »B«();
}

0 comments on commit 23d960f

Please sign in to comment.