diff --git a/packages/concerto-core/lib/introspect/classdeclaration.js b/packages/concerto-core/lib/introspect/classdeclaration.js index 95025494e2..acd6bb7b4d 100644 --- a/packages/concerto-core/lib/introspect/classdeclaration.js +++ b/packages/concerto-core/lib/introspect/classdeclaration.js @@ -225,18 +225,20 @@ class ClassDeclaration extends Decorated { if (idField.isOptional()) { throw new IllegalModelException('Identifying fields cannot be optional.', this.modelFile, this.ast.location); } - if (this.getSuperType()) { - const superType = this.getModelFile().getType(this.superType); - if(this.isSystemIdentified()) { - // check that the super type is also system identified - if(!superType.isSystemIdentified()) { - throw new IllegalModelException(`Super class has an explicit identifier ${superType.getIdentifierFieldName()} that cannot be redeclared.`, this.modelFile, this.ast.location); + if(this.superType) { + const superType = this.getModelFile().getType(this.superType); + if (superType && superType.getIdentifierFieldName() ) { + if(this.isSystemIdentified()) { + // check that the super type is also system identified + if(!superType.isSystemIdentified()) { + throw new IllegalModelException(`Super class ${superType.getFullyQualifiedName()} has an explicit identifier ${superType.getIdentifierFieldName()} that cannot be redeclared.`, this.modelFile, this.ast.location); + } } - } - else { - if(superType.isExplicitlyIdentified()) { - throw new IllegalModelException(`Super class has an explicit identifier ${superType.getIdentifierFieldName()} that cannot be redeclared.`, this.modelFile, this.ast.location); + else { + if(superType.isExplicitlyIdentified()) { + throw new IllegalModelException(`Super class ${superType.getFullyQualifiedName()} has an explicit identifier ${superType.getIdentifierFieldName()} that cannot be redeclared.`, this.modelFile, this.ast.location); + } } } } diff --git a/packages/concerto-core/lib/introspect/identifieddeclaration.js b/packages/concerto-core/lib/introspect/identifieddeclaration.js index 0620d51b89..a1ec6e4d7a 100644 --- a/packages/concerto-core/lib/introspect/identifieddeclaration.js +++ b/packages/concerto-core/lib/introspect/identifieddeclaration.js @@ -36,6 +36,7 @@ class IdentifiedDeclaration extends ClassDeclaration { constructor(modelFile, ast) { super(modelFile, ast); this._isIdentifiedDeclaration = true; + this.process(); } /** @@ -47,7 +48,7 @@ class IdentifiedDeclaration extends ClassDeclaration { process() { super.process(); - if(!this.superType && !this.idField) { + if(this.superType === 'Concept' && !this.idField) { this.idField = '$identifier'; this.addIdentifierField(); } diff --git a/packages/concerto-core/test/introspect/classdeclaration.js b/packages/concerto-core/test/introspect/classdeclaration.js index 5bbaf9650f..f8ec5c3310 100644 --- a/packages/concerto-core/test/introspect/classdeclaration.js +++ b/packages/concerto-core/test/introspect/classdeclaration.js @@ -92,7 +92,7 @@ describe('ClassDeclaration', () => { let asset = introspectUtils.loadLastDeclaration('test/data/parser/classdeclaration.identifierextendsfromsupertype.cto', AssetDeclaration); (() => { asset.validate(); - }).should.throw(/Super class has an explicit identifier a1 that cannot be redeclared/); + }).should.throw(/Super class com.testing.p1 has an explicit identifier a1 that cannot be redeclared/); }); // TODO: This has been disabled pending major version bump and/or confirmation that this is illegal diff --git a/packages/concerto-core/test/introspect/identifieddeclaration.js b/packages/concerto-core/test/introspect/identifieddeclaration.js index ce8b77c069..dbdf390a76 100644 --- a/packages/concerto-core/test/introspect/identifieddeclaration.js +++ b/packages/concerto-core/test/introspect/identifieddeclaration.js @@ -114,7 +114,7 @@ asset Order identified by sku { } `, 'test.cto'); - }).should.throw(/Super class has an explicit identifier sku that cannot be redeclared./); + }).should.throw(/Super class test.Order has an explicit identifier sku that cannot be redeclared./); }); it('should not allow overriding system identifier', () => { @@ -153,7 +153,7 @@ asset Order identified by sku { } `, 'test.cto'); - }).should.throw(/Super class has an explicit identifier sku that cannot be redeclared./); + }).should.throw(/Super class test.Order has an explicit identifier sku that cannot be redeclared./); }); it('should not allow overriding explicit identifier with an explicit identifier', () => { @@ -173,7 +173,7 @@ asset Order identified by sku { } `, 'test.cto'); - }).should.throw(/Super class has an explicit identifier sku that cannot be redeclared./); + }).should.throw(/Super class test.Order has an explicit identifier sku that cannot be redeclared./); }); it('should not allow field called $identifier', () => {