Skip to content

Commit

Permalink
fix(parser): throw error when concept is extending itself in JSON met…
Browse files Browse the repository at this point in the history
…amodel form

Signed-off-by: Stefan Blaginov <[email protected]>
  • Loading branch information
Stefan Blaginov authored and Stefan Blaginov committed Nov 22, 2023
1 parent 02da293 commit 7a9d181
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/concerto-cto/lib/printer.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,9 @@ function declFromMetaModel(mm) {
}
}
if (mm.superType) {
if (mm.superType.name === mm.name) {
throw new Error(`The declaration "${mm.name}" cannot extend itself.`);
}
result += `extends ${mm.superType.name} `;
}
result += '{';
Expand Down
26 changes: 26 additions & 0 deletions packages/concerto-cto/test/printer.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,30 @@ describe('parser', () => {
declarations: [],
})).should.throw(Error, 'Unrecognized import');
});

it('Should throw error for a self-extending declaration', () => {
(() => Printer.toCTO({
'$class': '[email protected]',
'namespace': '[email protected]',
'declarations': [
{
'$class': '[email protected]',
'name': 'Self_Extending',
'isAbstract': false,
'properties': [
{
'$class': '[email protected]',
'name': 'foo',
'isArray': false,
'isOptional': true
}
],
'superType': {
'$class': '[email protected]',
'name': 'Self_Extending'
}
}
]
})).should.throw(Error, 'The declaration "Self_Extending" cannot extend itself.');
});
});

0 comments on commit 7a9d181

Please sign in to comment.