accordproject / concerto

Business schema language and runtime
https://concerto.accordproject.org
Apache License 2.0
121 stars 106 forks source link

Error when attempting extend Concept to Clause or Contract #676

Open martinhalford opened 1 year ago

martinhalford commented 1 year ago

Bug Report 🐛

Tried this in Template Playground.

For following model.cto...

namespace hello@1.0.0

import org.accordproject.contract@0.2.0.Contract from https://models.accordproject.org/accordproject/contract@0.2.0.cto

@template
concept HelloWorld extends Contract {
    o String name
}

...getting error...

D: ConceptDeclaration (HelloWorld) cannot extend AssetDeclaration (Contract) Line 5 column 1, to line 8 column 2.

Is extends no longer required and/or been superseded / deprecated?

(Note: If this is the case then suspect some of our CodeGen logic will fail / need refactoring.)

image

mttrbrts commented 1 year ago

Please try

Asset HelloWorld extends Contract

martinhalford commented 1 year ago

Hi @mttrbrts -

I tried asset....

namespace hello@1.0.0

import org.accordproject.contract@0.2.0.Contract from https://models.accordproject.org/accordproject/contract@0.2.0.cto

@template
asset HelloWorld extends Contract {
    o String name
}

...now getting error...

Error: Invalid or missing identifier for Type "HelloWorld" in namespace "hello@1.0.0".

After reading some doco, I also tried...

namespace hello@1.0.0

import org.accordproject.contract@0.2.0.Contract from https://models.accordproject.org/accordproject/contract@0.2.0.cto

@template
asset HelloWorld identified by name extends Contract {
    o String name
}

...but then got the error...

D: Super class org.accordproject.contract@0.2.0.Contract has an explicit identifier contractId that cannot be redeclared. Line 5 column 1, to line 8 column 2.

For the record, was trying these models in https://playground.accordproject.org/ for ease and simplicity. However, I think the same happens in the CLI too.

Any ideas?

dselman commented 1 year ago

The concept org.accordproject.contract@0.2.0.Contract already has an identifying field, so you cannot redeclare or override it for HelloWorld.

This works:

namespace hello@1.0.0

import org.accordproject.contract@0.2.0.Contract from https://models.accordproject.org/accordproject/contract@0.2.0.cto

@template
asset HelloWorld extends Contract {
    o String name
}

With this JSON data:

{
  "$class": "hello@1.0.0.HelloWorld",
  "contractId" : "foo",
  "name": "John Doe"
}

What would make the debugging simpler is if we highlight which file is raising an error in the Playground...

martinhalford commented 1 year ago

Hi @dselman - Yes - that makes sense. I only tried redeclaring the id field in an attempt to get the above to work.

Sadly, the model syntax above doesn't work for archive for Cicero version 0.24.1-20230722135139.

namespace hello@1.0.0

import org.accordproject.contract@0.2.0.Contract from https://models.accordproject.org/accordproject/contract@0.2.0.cto

@template
asset HelloWorld extends Contract {
    o String name
}

This is what I get when I try to execute the archive method on the cicero cli.

% cicero --version
0.24.1-20230722135139
% cicero archive
11:41:24 am - INFO: Using current directory as template folder
11:41:25 am - ERROR: Failed to find an asset that extends org.accordproject.contract.Contract. The model for the template must contain a single asset that extends org.accordproject.contract.Contract.

(cc: @mttrbrts)

martinhalford commented 1 year ago

Suspect these issues are related. https://github.com/accordproject/cicero/issues/791

@dselman @mttrbrts