Repository navigation
binding: report ambiguous members of variant base interfaces - #56
Merged
Merged
Conversation
HidesMethodsOf in MethodResolver combined two rules: finding base types by inheritance and letting a method of a class other than Object remove the methods of interfaces. Move the first rule to ReflectionExtensions.IsBaseTypeOf, so that only the rule specific to method invocation stays in MethodResolver and member lookup can use the same check. No behavior change.
A field or property hid the members with the same name declared in any type assignable from its declaring type, and assignability takes variance into account. With a covariant IProducer<out T> declaring T Value and IBothProducers : IProducer<object>, IProducer<string>, IProducer<object> is assignable from IProducer<string>, so P.Value silently bound to IProducer<string>.Value. C# reports an ambiguity (CS0229): neither instantiation is a base interface of the other. Use IsBaseTypeOf, which finds base types by inheritance, as for methods. It never treats a type as its own base type, so the separate check for the same declaring type is no longer needed. Classes were not affected, since they cannot be variant.
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.
A field or property hid the members with the same name declared in any type assignable from its declaring type, and assignability takes variance into account. For a covariant
IProducer<out T>withT Value { get; }andIBothProducers : IProducer<object>, IProducer<string>,IProducer<object>is assignable fromIProducer<string>, soP.Valuesilently bound toIProducer<string>.Valueand got the typestring. C# reports CS0229: neither instantiation is a base interface of the other. Classes were not affected, since they cannot be variant.This PR moves the base type check that
MethodResolverhas used for method hiding since #54 toReflectionExtensions.IsBaseTypeOf, which finds base types by inheritance, and uses it inBindToMemberas well.MethodResolverkeeps only the rule specific to method invocation: a method of a class other thanObjectremoves the methods of interfaces. The member filter no longer needs a separate check for the same declaring type.