ST6RI-728 Name resolution of multiply inherited redefined features is not correct #686
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.
This PR resolves an anomaly in the resolution of the name of a redefined feature due to certain forms of diamond specialization. This anomaly was because the name resolution algorithm (in
org.omg.kerml.xtext.scoping.KerMLScope
) traverses the specialization hierarchy without using the derived property computation of inherited memberships, but it was not updated when the inherited membership computation was revised to handle multiply inherited redefinitions per the specification.Problem
Consider the following KerML model:
Previously, this model generated the indicated error, because the name resolution algorithm traversed specializations in order, stopping if it found a resolution for the name. Thus, since
C
specializesA
beforeB
, the featuref
inherited byC
wasA::f,
which does not include the nested featureg
. But, if the order of the specialized types was changed fromA, B
toB, A
, then the error would go away, becauseB::f
was now inherited instead.Fix
In order to remove the dependency on the order of specializations, the name resolution algorithm was updated to traverse all specializations of a type, not stopping if a resolution is found. Instead, each time a potentially resolving element is found, it is compared to the previously found resolution (if any), and if the new element is a feature that directly or indirectly redefines the old element, then the new element replaces the old one as the found resolution. Note that this means that, if there are multiple features found none of which redefine another (i.e., conflicting inherited features), the resolution algorithm still returns the first one.
Due to previous optimizations in the computation of redefined features, the update in this PR seems to have no cause no degradation in performance.