Interface implementations can be provided by the component#10932
Open
0x6e wants to merge 3 commits intoslint-ui:masterfrom
Open
Interface implementations can be provided by the component#109320x6e wants to merge 3 commits intoslint-ui:masterfrom
0x6e wants to merge 3 commits intoslint-ui:masterfrom
Conversation
…ions Previously, when a component declares that it implements an interface the compiler would emit errors if the inherited component had properties/callbacks/functions that collided with the interface. Now, we check whether the implementation in the inherited component matches that of the interface and allow the existing implementation to be used instead. The exception to this behaviour is how the default property bindings are applied. The current behaviour is that the component with the `implements` keyword specifies the default binding. This is shown in `tests/cases/interfaces/derived_implicitly_implements.slint`: - InterfaceWithDefaults specifies `precision: 2;` and `confidence: 1.0;`; - Base specifies `precision;` and `confidence: 0.5;` - TestCase (which has the implements keyword) specifies `precision: 3;` - TestCase expects `self.precision == 3 && self.confidence == 1.0;`. Precision comes from the TestCase default whilst confidence comes from the interface default. This behaviour is up for discussion, but largely driven by the following constraints: - if we specify a default in the interface, e.g. `enabled: true`, but don't specify anything in the implementing component, we would expect the default to match the interface. Prior to `3b04cf978` the default would have been `false`; - the current code doesn't provide a mechanism for us to check the bindings of a derived component - we can only query the property declarations.
…arations Previously the compiler would emit an error if a component provided a property or callback that matched one defined in an implemented interface. This change allows a component to provide an implementation of a property or callback, as long as it matches the implementation specified in the interface. To support this we need to interleave the parsing of the element property declarations, bindings and callbacks with those of the interface. This ensures that if a component provides a default property binding for a property, but not the implementation, the implementation is provided by the interface before the compiler attempts to add the binding.
Don't refer to interfaces in these function names. We can use the module name to provide context.
09c6f5a to
f3c0a9c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Prior to this change interface implementations for properties and callbacks could only be provided by the compiler. This PR allows a component or the components it inherits from to provide the interface API. The compiler verifies that the provided implementation matches the interface, otherwise an error is emitted.
This change is necessary to allow us to implement the CheckBox interface in the Qt std-widgets style like this:
We don't currently have a way to say that native widgets implement an interface. The proposed solution is to say that
CheckBoximplements it, and allowNativeCheckBoxto provide the implementation.One consequence of this PR is that we must make a decision about how default property bindings are provided. The current behaviour is that the component with the
implementskeyword specifies the default binding. This is shown intests/cases/interfaces/derived_implicitly_implements.slint:precision: 2;andconfidence: 1.0;;precision;andconfidence: 0.5;precision: 3;self.precision == 3 && self.confidence == 1.0;.Precision comes from the TestCase default whilst confidence comes from the interface default.
This behaviour is up for discussion, but largely driven by the following constraints:
enabled: true, but don't specify anything in the implementing component, we would expect the default to match the interface. Prior to3b04cf978the default would have beenfalse;