Skip to content

binding: let derived class fields and properties hide base members - #53

Merged
rameel merged 1 commit into
mainfrom
binding/derived-class-member-hiding
Nov 21, 2026
Merged

rameel merged 1 commit into
mainfrom
binding/derived-class-member-hiding

Conversation

@rameel

@rameel rameel commented Nov 21, 2026

Copy link
Copy Markdown
Owner

A field or property redeclared in a derived class could not be accessed. For a class, Type.GetMembers returns both the member of the derived class and the base class member it hides, so the lookup reported an ambiguous match. For a context member Derived of a class that redeclares int Field with new and replaces int Property with new string Property, Derived.Field and Derived.Property failed with "Ambiguous match found", and so did Field when the context object itself was of that class. A property redeclared with the same type was not affected: reflection drops the hidden property itself.

This PR applies the rule that #50 added for interfaces to classes: as in C#, a field or property of a derived class hides the members with the same name of its base classes.

Members of statically imported types are still not filtered. A name declared in two imported types stays ambiguous even if one type derives from the other, like CS0229 with using static in C#.

For a class, Type.GetMembers returns a field of a derived class along
with the base class field it hides, and likewise for a property unless
both properties have the same type. Accessing such a member, through a
value or by an unqualified name in the context, failed with "Ambiguous
match found".

As in C#, a field or property of a derived class now hides the members
with the same name of its base classes, as it already did for derived
interfaces. Members of statically imported types are still not
filtered: a name declared in two imported types is ambiguous even if
one type derives from the other, as with using static in C#.
@rameel
rameel merged commit 34dcde2 into main Nov 21, 2026
1 check passed
@rameel
rameel deleted the binding/derived-class-member-hiding branch November 21, 2026 11:54
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

Successfully merging this pull request may close these issues.

1 participant