- 
          
 - 
                Notifications
    
You must be signed in to change notification settings  - Fork 583
 
Description
Version/platform/runtime used
Jint 4.1.0 / NET 9.0.302
Describe the bug
When indexer is present, Evaluate only considers the declared type of a property, not the type of the value. So if the property is declared as type Wrapper, but the value assigned is a subclass of Wrapper, Jint still treats it like a Wrapper type.
To Reproduce
Create a class called Wrapper with a dictionary indexer
private readonly IDictionary<string, object?> _exports = new Dictionary<string, object?>();
/// <summary>
/// Indexer that makes exports available.
/// </summary>
public object? this[string name]
{
    get
    {
        if (_exports.ContainsKey(name))
        {
            return _exports[name];
        }
        return null;
    }
    set
    {
        _exports[name] = value;
    }
}
Then create a class called GeometryWrapper that subclasses Wrapper. Have GeometryWrapper declare a double property like public double X { get; }, set it to some value in GeometryWrapper's constructor. Then create a class called Feature that has a property public Wrapper Geometry { get; set; }.
Finally, in main, try to evaluate feature.geometry.x.
var engine = new Engine();
var feature = new Feature();
var geometryWrapper = new GeometryWrapper();
engine.SetValue("feature", feature);
feature.Geometry = geometryWrapper;
var x = engine.Evaluate("feature.geometry.x");
Expected behavior
Since feature.geometry.x's value is a GeometryWrapper, we would expect feature.geometry.x to be a double.
Additional context
Instead of a double, feature.geometry.x is null. It seems like Jint thinks feautre.geometry is of type Wrapper so it only searched the indexer for x. But in fact feature.geometry is GeometryWrapper so it should have an X property.
I also found that if X is declared as an abstract property in Wrapper and let GeometryWrapper implement it, then X can be found. Removing the indexer from Wrapper also fixes the issue.