Skip to content

Exception in DescriptorBuilder for extension with redefines #38

@fra-pa

Description

@fra-pa

Trying to get type information or create an instance of a type (c:CustomRoot) which extends another type (b:Root), inherits from a base type (c:Base) and redefines a property (b:Root#generic), the following exception is thrown:

Error: refined property <b:generic> not found
      at DescriptorBuilder._545‍.r.DescriptorBuilder.redefineProperty (lib/descriptor-builder.js:125:11)
      at DescriptorBuilder.<anonymous> (lib/descriptor-builder.js:219:12)
      at forEach (node_modules/min-dash/dist/index.js:170:20)
      at DescriptorBuilder._545‍.r.DescriptorBuilder.addTrait (lib/descriptor-builder.js:202:3)
      at lib/registry.js:185:13
      at Registry._a72‍.r.Registry.mapTypes (lib/registry.js:165:3)
      at Registry._a72‍.r.Registry.getEffectiveDescriptor (lib/registry.js:184:8)
      at Moddle._a72‍.r.Moddle.getType (lib/moddle.js:97:32)
      at Context.<anonymous> (test/spec/extension.js:58:28)
      at processImmediate (internal/timers.js:461:21)

DescriptorBuilder fails to lookup property b:Root#generic in propertiesByName, because b:Root is not a superClass of c:Base and therefore not found in the inheritance chain of c:CustomRoot.

The model (base.json and custom.json) used for the test looks something like this:

redefined-properties-ext-type

At runtime, the applied extension of b:Root by c:CustomRoot transforms the model (interpreted from the type descriptor Type.$descriptor; see below snippet from the spec) into:

redefined-properties-ext-type-b-root

Redefining properties of extended types is not explicitly documented, but specified in "moddle/extension/trait/should refine property":

it('should refine property', function() {
  // given
  var Type = model.getType('b:Root');

  // when
  var genericProperty = Type.$descriptor.propertiesByName['generic'];

  // then
  expect(genericProperty.type).to.eql('c:CustomGeneric');
});

The documentation describes the redefinition of properties:

redefines the property inherited from a super type, overriding name, type and qualifiers

This refers only to inheritance, not extension. c:CustomRoot uses both and it's explicitly tested, that the property b:Root#generic from the extendet type b:Root is redefined.

Maybe I miss something, but it should be possible, to getType() or create an instance of c:CustomRoot, right?

Regards,
Frank

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions