Skip to content

Generic type incorrectly detected as unknown identifier #312

@WAcry

Description

@WAcry

Description

When using the DetectIdentifiers method of the Interpreter, generic type (e.g. Tuple<>) is incorrectly detected as an unknown identifier, despite being properly referenced and Eval() works.

var target = new Interpreter();
target.Reference(typeof(Tuple<>));
target.Reference(typeof(Tuple<,>));
target.Reference(typeof(Tuple<,,>));
var expression = "new Tuple<int>(1).Item1";
var result = target.Eval(expression);
Console.WriteLine(result);  // 1
var detectedIdentifiers = target.DetectIdentifiers(expression);
Console.WriteLine(System.Text.Json.JsonSerializer.Serialize(detectedIdentifiers.UnknownIdentifiers)); // ["Tuple"]

I think we can add a KnownGenericTypes, and update DetectIdentifiers

else if (_settings.KnownGenericTypes.TryGetValue(identifier, out ReferenceType knownType))
	knownTypes.Add(knownType);

, but I'm not sure if there's an better fix. Could you take a look when you have time?

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions