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

✏️ Inconsistency between thrown exceptions of "required" and "conflicting" properties when instantiating traits? #14

Open
dwiyatci opened this issue Feb 23, 2019 · 0 comments

Comments

@dwiyatci
Copy link

Quoting the README:
(A)

  • an exception is thrown if 'trait' contains required properties.

(B)

  • an exception is thrown if 'trait' contains conflict properties.

However, when my prototype provides (or "implements") the required property, an exception is not thrown even though the composed trait contains required properties.

Snippet 1

const T1 = Trait({ a: Trait.required, b: 1 });
const T2 = Trait({ c: 2 });

const prototype = { a: 0 };

const instance = Trait.create(
  prototype,
  Trait.compose(
    T1,
    T2
  )
);
// { a: 0, b: 1, c: 2 }

This, though, seems to be inconsistent with "conflicting" properties mechanics (ok, statement (B) holds here, i.e. exception not thrown because the composed trait does not contain conflict properties).

Snippet 2

const T1 = Trait({ a: 42, b: 1 });
const T2 = Trait({ c: 2 });

const prototype = { a: 0 };

const instance = Trait.create(
  prototype,
  Trait.compose(
    T1,
    T2
  )
);
// { a: 42, b: 1, c: 2 }

Is this by design?

I would expect something more like:

  • an exception is thrown if 'instantiation' contains required properties.
  • an exception is thrown if 'instantiation' contains conflicting properties.

...in which snippet 1 is OK because the required a property is provided by the prototype, and snippet 2 should throw because property a in the composed trait and in the prototype are conflicting :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant