Skip to content

[wasm][debugger] Support indexing Dictionary by object key #76014

Description

@ilonatommy

Tests: in DebuggerTests.EvaluateOnCallFrameTests.EvaluateUserDefinedIndexingByNonIntLocals uncomment lines:

// ("f[aDecimal]", TNumber(3))

and fix. Decimal is treated as an object. We can handle indexing by it e.g. by adding in GetElementIndexInfo in case of (arg.Expression is IdentifierNameSyntax)

// indexObject={
//   "type": "object",
//   "value": null,
//   "description": "3.34",
//   "className": "System.Decimal",
//   "objectId": "dotnet:valuetype:9",
//   "isValueType": true
// }
                        if (indexObject["type"].ToString() == "object") // e.g. System.Decimal behaves this way
                        {
                            elementIdxStr.Append(indexObject["description"].ToString()); // or resolving value
                        }
                        else
                        {
                            elementIdxStr.Append(indexObject["value"].ToString());
                        }

But when one class has multiple indexers like we have in our tests, then in Task<JObject> Resolve(ElementAccessExpressionSyntax elementAccess, Dictionary<string, JObject> memberAccessValues, JObject indexObject, List<string> variableDefinitions, CancellationToken token) we'll get multiple "get_Item" methods. In case of Decimal, it is sent as 4th method out of 6 and the 2nd method is public bool this[string key3] => key3.Length > 3;. We are trying all possible methods till one works (does not throw an exception) and by coincidence the boolean-returning method does not throw. That's why we resolve a wrong value by mistake. We return

{
  "type": "boolean",
  "value": true,
  "description": "true",
  "className": "System.Boolean"
}

instead of "number" 3.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions