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

ArgumentException with nullable Enum #134

Closed
vlm--- opened this issue Nov 8, 2023 · 5 comments
Closed

ArgumentException with nullable Enum #134

vlm--- opened this issue Nov 8, 2023 · 5 comments
Assignees
Labels

Comments

@vlm---
Copy link

vlm--- commented Nov 8, 2023

Hello, version 4.1.1 indroduced some new bug with expressions containing nullable enums:

using System;
using System.Linq.Expressions;
using AgileObjects.ReadableExpressions;

public class Program
{
	public static void Main()
	{
		Expression<Func<Product, bool>> exp = p => p.Level == ProductLevel.Classic;
		Console.WriteLine(exp.ToReadableString());
	}

	public enum ProductLevel
	{
		Classic,
		Premium
	}

	public class Product
	{
		public ProductLevel? Level { get; set; }
	}
}
System.ArgumentException: Type provided must be an Enum. (Parameter 'enumType')
   at System.Enum.ValidateRuntimeType(Type enumType)
   at System.Enum.TryParse(Type enumType, ReadOnlySpan`1 value, Boolean ignoreCase, Boolean throwOnFailure, Object& result)
   at System.Enum.Parse(Type enumType, String value)
   at AgileObjects.ReadableExpressions.Translations.BinaryTranslation.GetEnumValue(Expression expression, Type enumType)
   at AgileObjects.ReadableExpressions.Translations.BinaryTranslation.TryGetEnumComparisonExpression(BinaryExpression& comparison)
   at AgileObjects.ReadableExpressions.Translations.BinaryTranslation.For(BinaryExpression binary, ITranslationContext context)
   at AgileObjects.ReadableExpressions.Translations.ExpressionTranslation.GetDefaultTranslation(Expression expression)
   at AgileObjects.ReadableExpressions.Translations.ExpressionTranslation.GetTranslationFor(Expression expression)
   at AgileObjects.ReadableExpressions.Extensions.PublicTranslationContextExtensions.GetCodeBlockTranslationFor(ITranslationContext context, Expression expression)
   at AgileObjects.ReadableExpressions.Translations.LambdaTranslation..ctor(LambdaExpression lambda, ITranslationContext context)
   at AgileObjects.ReadableExpressions.Translations.ExpressionTranslation.GetDefaultTranslation(Expression expression)
   at AgileObjects.ReadableExpressions.Translations.ExpressionTranslation.GetTranslationFor(Expression expression)
   at AgileObjects.ReadableExpressions.Translations.ExpressionTranslation.GetTranslation()
   at AgileObjects.ReadableExpressions.ExpressionExtensions.ToReadableString(Expression expression, Func`2 configuration)
   at Program.<<Initialize>>d__0.MoveNext() in :line 11

Example works perfectly with version 4.1.0:
p => ((int?)p.Level) == ((int?)Program.ProductLevel.Classic)

@EvgenyMarchuk
Copy link

EvgenyMarchuk commented Nov 9, 2023

+1, The same problem
or you can get it when usу LINQ All, Any ...

.All(i => i.Type == SomeType.TypeOne) and property is nullable

@SteveWilkes
Copy link
Member

Darnit - this is a regression introduced by #129 - I'll fix this and #133 asap.

@SteveWilkes SteveWilkes self-assigned this Nov 9, 2023
@SteveWilkes SteveWilkes added the bug label Nov 9, 2023
@SteveWilkes SteveWilkes added the in-branch A feature or bug fix exists in code, and a release will follow label Nov 10, 2023
@EvgenyMarchuk
Copy link

Hi! When are you going to merge the fix?
Thanks.

@SteveWilkes
Copy link
Member

Hi @EvgenyMarchuk! I'm still working on processing captured values correctly and trying to nail down how that feature behaves in a wider sense. Hoping to have it sorted out soon, along with #135

SteveWilkes added a commit that referenced this issue Jun 22, 2024
* Fixing nullable enum translation, re: #134

* Extending ShowCapturedValues capabilities

* Adding .NET 8 test project

* Fixing parameterless Value Tuple translation, re: #135

* Tidy

* Fixing non-equality enum comparisons, re #136

* v4.1.2

* Release notes

---------

Co-authored-by: Steve Wilkes <[email protected]>
@SteveWilkes
Copy link
Member

This is fixed as of v4.1.2, which is now available on NuGet. Cheers!

@SteveWilkes SteveWilkes removed the in-branch A feature or bug fix exists in code, and a release will follow label Jun 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants