Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generic type incorrectly detected as unknown identifier #312

Open
WAcry opened this issue Jul 21, 2024 · 1 comment
Open

Generic type incorrectly detected as unknown identifier #312

WAcry opened this issue Jul 21, 2024 · 1 comment

Comments

@WAcry
Copy link

WAcry commented Jul 21, 2024

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?

@davideicardi
Copy link
Member

Thank you @WAcry for the bug report and fix. If you could create a PR I will appreciate it. Otherwise I will try to work on it in the future.

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

No branches or pull requests

2 participants