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

  1. added this to the 8.0.0 milestone on Sep 22, 2022
  2. self-assigned this
    on Sep 22, 2022
  3. changed the title [-][wasm[[debugger] Support indexing Dictionary by object key[/-] [+][wasm][debugger] Support indexing Dictionary by object key[/+] on Sep 22, 2022
  4. modified the milestones: 8.0.0, 9.0.0 on Aug 7, 2023
  5. ghost added
    in-prThere is an active PR which will close this issue when it is merged
    on Aug 9, 2023
  6. ghost removed
    in-prThere is an active PR which will close this issue when it is merged
    on Aug 14, 2023
  7. ghost locked as resolved and limited conversation to collaborators on Sep 14, 2023
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