diff --git a/packages/concerto-core/lib/introspect/modelfile.js b/packages/concerto-core/lib/introspect/modelfile.js index f582b05e6e..8012d8e8c8 100644 --- a/packages/concerto-core/lib/introspect/modelfile.js +++ b/packages/concerto-core/lib/introspect/modelfile.js @@ -275,19 +275,19 @@ class ModelFile extends Decorated { // Validate all of the types in this model file. // Check if names of the declarations are unique. const uniqueNames = new Set(); - this.declarations.forEach( - d => { - const fqn = d.getFullyQualifiedName(); - if (!uniqueNames.has(fqn)) { - uniqueNames.add(fqn); - } else { - throw new IllegalModelException( - `Duplicate class name ${fqn}` - ); - } + this.declarations.forEach(d => { + const fqn = d.getFullyQualifiedName(); + const shortName = ModelUtil.getShortName(fqn); + if (uniqueNames.has(fqn)) { + throw new IllegalModelException(`Duplicate class name: ${fqn}`); } - ); - + if (this.importShortNames.has(shortName)) { + throw new IllegalModelException( + `TypeName Conflict: The type '${shortName}' is being redefined, but it already exists as an imported type from '${this.importShortNames.get(shortName)}'. Please rename your local type or avoid importing conflicting types.` + ); + } + uniqueNames.add(fqn); + }); // Run validations on class declarations for(let n=0; n < this.declarations.length; n++) { let classDeclaration = this.declarations[n]; diff --git a/packages/concerto-core/test/composer/composermodel.js b/packages/concerto-core/test/composer/composermodel.js index 6bd0365e82..96cc8d82b3 100644 --- a/packages/concerto-core/test/composer/composermodel.js +++ b/packages/concerto-core/test/composer/composermodel.js @@ -33,16 +33,16 @@ const COMPOSER_MODEL = */ namespace system -event Event { +event newEvent { } -participant Participant { +participant newParticipant { } -asset Asset { +asset newAsset { } -transaction Transaction { +transaction newTransaction { } /** diff --git a/packages/concerto-core/test/data/parser/classdeclaration.dupeassetname.cto b/packages/concerto-core/test/data/parser/classdeclaration.dupeassetname.cto index f58438bc7c..9ac9c8a2f4 100644 --- a/packages/concerto-core/test/data/parser/classdeclaration.dupeassetname.cto +++ b/packages/concerto-core/test/data/parser/classdeclaration.dupeassetname.cto @@ -14,12 +14,12 @@ namespace com.testing -asset Asset identified by id { +asset newAsset identified by id { o String id o String newValue } -asset Asset identified by id { +asset newAsset identified by id { o String id o String newValue } \ No newline at end of file diff --git a/packages/concerto-core/test/data/parser/classdeclaration.dupeconceptname.cto b/packages/concerto-core/test/data/parser/classdeclaration.dupeconceptname.cto index 93487093db..525cd2c12f 100644 --- a/packages/concerto-core/test/data/parser/classdeclaration.dupeconceptname.cto +++ b/packages/concerto-core/test/data/parser/classdeclaration.dupeconceptname.cto @@ -14,12 +14,12 @@ namespace com.testing -concept Concept{ +concept newConcept{ o String id o String newValue } -concept Concept{ +concept newConcept{ o String id o String newValue } \ No newline at end of file diff --git a/packages/concerto-core/test/introspect/classdeclaration.js b/packages/concerto-core/test/introspect/classdeclaration.js index 1faafe0520..a785c88ace 100644 --- a/packages/concerto-core/test/introspect/classdeclaration.js +++ b/packages/concerto-core/test/introspect/classdeclaration.js @@ -336,7 +336,7 @@ describe('ClassDeclaration', () => { describe('#_resolveSuperType', () => { it('should return Asset if no super type', () => { - let classDecl = modelManager.getType('system.Asset'); + let classDecl = modelManager.getType('system.newAsset'); classDecl._resolveSuperType().should.not.be.null; }); @@ -373,7 +373,7 @@ describe('ClassDeclaration', () => { describe('#getSuperTypeDeclaration', () => { it('should return Concept if no super type', () => { - let classDecl = modelManager.getType('system.Asset'); + let classDecl = modelManager.getType('system.newAsset'); classDecl.getSuperTypeDeclaration().should.not.be.null; }); }); diff --git a/packages/concerto-core/test/model/concept-identified.js b/packages/concerto-core/test/model/concept-identified.js index 656459239d..e794398425 100644 --- a/packages/concerto-core/test/model/concept-identified.js +++ b/packages/concerto-core/test/model/concept-identified.js @@ -42,7 +42,7 @@ describe('Concept Identifiers', function () { --> Product product } transaction Request {} - event Event {} + event newEvent {} `, 'test.cto'); classDecl = modelManager.getType('org.accordproject.Order'); }); @@ -98,7 +98,7 @@ describe('Concept Identifiers', function () { const txn = factory.newResource('org.accordproject', 'Request'); dayjs(txn.getTimestamp()).isValid().should.be.true; - const event = factory.newResource('org.accordproject', 'Event'); + const event = factory.newResource('org.accordproject', 'newEvent'); dayjs(event.getTimestamp()).isValid().should.be.true; });