Skip to content

Commit

Permalink
Don't find hidden property instead of the hiding property
Browse files Browse the repository at this point in the history
When `TypeResolver:TryFindMemberAccessor` resolves a property, it might find one that was hidden where the non-hidden one would normally be found by C++ member access.

For example, when you access the `A` member from JavaScript, you may get the hidden one (I say "may" because `Type:GetProperties` does not specify an order in a number of versions of .NET supported by jint).

```
class Foo
{
    public int A {get;set;}
    public string B {get;set;}
}

class Bar :  Foo
{
	public new float A { get; set; }
}
```

([This dotnet fiddle](http://dotnetfiddle.net/NQRXIJ) shows that both `A` elements are iterated by `GetProperties` even though if `b` is a `Bar`, `b.A` unambiguously refers to `Bar:A`)

This change ensures that in the case where a property in a derived class hides another, the derived one is resolved to.
  • Loading branch information
mspertus committed Sep 4, 2024
1 parent 3c4af55 commit 14ab9bc
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Jint/Runtime/Interop/TypeResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,14 @@ internal bool TryFindMemberAccessor(
{
if (memberNameComparer.Equals(name, memberName))
{
// If one property hides another (e.g., by public new), the derived property is returned.
if (property is not null
&& p.DeclaringType is not null
&& property.DeclaringType is not null
&& property.DeclaringType.IsSubclassOf(p.DeclaringType))
{
continue;
}
property = p;
break;
}
Expand Down

0 comments on commit 14ab9bc

Please sign in to comment.