Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(introspect): redefining imported type (#871) #901

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions packages/concerto-core/lib/introspect/modelfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
8 changes: 4 additions & 4 deletions packages/concerto-core/test/composer/composermodel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
4 changes: 2 additions & 2 deletions packages/concerto-core/test/introspect/classdeclaration.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});

Expand Down Expand Up @@ -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;
});
});
Expand Down
4 changes: 2 additions & 2 deletions packages/concerto-core/test/model/concept-identified.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe('Concept Identifiers', function () {
--> Product product
}
transaction Request {}
event Event {}
event newEvent {}
`, 'test.cto');
classDecl = modelManager.getType('org.accordproject.Order');
});
Expand Down Expand Up @@ -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;
});

Expand Down
Loading