Repository navigation
binding: find inherited static members through the derived class name - #55
Merged
Merged
Conversation
Overload resolution chose the most specific of all applicable methods, wherever they were declared. With BaseClass.M(int) and DerivedClass.M(long), Cls.M(1) called BaseClass.M(int), and the same happened with indexers and methods of base interfaces. C# calls DerivedClass.M(long): it removes the applicable methods declared in a base type of the type that declares another applicable method before choosing the best one. Apply this rule in MethodResolver. As in C#, an override belongs to the type that introduced the method. This includes a covariant return override, which reflection reports as a new method of the derived class and which is chosen over the method it overrides. Base types are found by inheritance rather than assignability, so instantiations of a variant interface do not hide each other. A method of a class other than Object also removes the methods of statically imported interfaces. The hierarchy depth no longer decides between methods with the same parameters. The same method imported from two unrelated types is now an ambiguous match, as in C#, instead of resolving to the type with the deeper hierarchy.
Static members were looked up without BindingFlags.FlattenHierarchy, so the static members of base classes were not found through the name of a derived class: with S declared in BaseClass, DerivedClass.S() failed with "Cannot resolve symbol 'S'", and so did string.ReferenceEquals(a, b). As in C#, a type name now gives access to the static members of its base classes, including Object, and an enum name to those of System.Enum. Members hidden with new still resolve to the derived class. Unqualified names still use only the static members declared by the imported types, as with using static in C#.
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.
Static members of base classes were not found through the name of a derived class. With a static method
Sdeclared inBaseClassandDerivedClassregistered withRegisterType,DerivedClass.S()failed with "Cannot resolve symbol 'S'", and so didstring.ReferenceEquals(a, b). For interfaces, #50 already made this work.This PR looks up static members through a type name with
BindingFlags.FlattenHierarchy, as C# does. A field, property, or method hidden withnewstill resolves to the member of the derived class. The static methods ofSystem.Enumare now available through an enum name, andstring.Equals(1, 1)callsObject.Equals(object, object)and returnstrueinstead of reporting an ambiguous match.Unqualified names still use only the static members declared by the imported types:
using staticin C# does not import members of base classes either.This relies on #54: without it, now that base class methods are visible,
DerivedClass.M(1)would chooseBaseClass.M(int)overDerivedClass.M(long).