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

cast / parentheses causing null coalescing usage failure #157

Open
mrtristan opened this issue Apr 30, 2024 · 2 comments
Open

cast / parentheses causing null coalescing usage failure #157

mrtristan opened this issue Apr 30, 2024 · 2 comments
Assignees

Comments

@mrtristan
Copy link

stripped down to a relatively minimal block to show the issue.

error: Oops! No applicable member has been found for the expression. The error occurred for expression "?." at position 59 near "?.ToString(\"g\");

const string mutationScript = """
// throws exception
	dict["CreatedOn"] = ((DateTime?)dict["CreatedOn"])?.ToString("g");
// works
	//	dict["CreatedOn"] = dict["CreatedOn"]?.ToString("g");
""";

var dicts = new[] {
	new Dictionary<string, object>()
	{
		{ "CreatedOn", DateTime.Now }
	},
	new Dictionary<string, object>()
	{
		{ "CreatedOn", null }
	}
};

var evalContext = new EvalContext
{
	SafeMode = true
};
evalContext.UnregisterAll();
evalContext.RegisterDefaultAliasSafe();
evalContext.RegisterType(
	typeof(IDictionary<string, object>),
	typeof(string),
	typeof(DateTime?)
);

var compiled = evalContext.Compile<Action<IDictionary<string, object>>>(
	   mutationScript,
	   "dict"
	  );

foreach(var dict in dicts) {
	compiled(dict);	
}
@mrtristan mrtristan changed the title cast / parenthesis causing null coalescing usage failure cast / parentheses causing null coalescing usage failure Apr 30, 2024
@JonathanMagnan JonathanMagnan self-assigned this Apr 30, 2024
@JonathanMagnan
Copy link
Member

Hello @mrtristan ,

Thank you for reporting; I can confirm I successfully reproduced this issue with your code, so we will look at it.

Best Regards,

Jon

@JonathanMagnan
Copy link
Member

Hello @mrtristan ,

The v6.1.4 has been released.

Could you let us know if my developer fixed the issue correctly?

Best Regards,

Jon

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

No branches or pull requests

2 participants