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

Flags enum with bitwise operator returns as int; should be the enum type #695

Closed
jbhelm opened this issue Mar 29, 2023 · 1 comment
Closed
Assignees
Labels

Comments

@jbhelm
Copy link

jbhelm commented Mar 29, 2023

When using bitwise operators on a flags enum, the resulting type is int, but it should be the enum type.

Here's a repro:

namespace DynamicLinqExample {
    public class Example {
        [Flags]
        public enum ExampleFlags {
            None = 0,
            A = 1,
            B = 2,
            C = 4,
            D = 8,
        };

        [Fact]
        public void FlagsEnumBitwiseOperatorsWrongResultType() {
            var query = new[] { 0 }.AsQueryable();

            var result1 = query.Select(x => ExampleFlags.A | ExampleFlags.B).First();
            Assert.IsType<ExampleFlags>(result1);    // <-- succeeds

            var result2 = query.Select("@0 | @1", ExampleFlags.A, ExampleFlags.B).First();
            Assert.IsType<ExampleFlags>(result2);    // <-- fails; type is int
        }
    }
}

This results in:

    Assert.IsType() Failure
    Expected: DynamicLinqExample.Example+ExampleFlags
    Actual:   System.Int32

Thanks!

@StefH StefH self-assigned this Jun 23, 2023
@StefH StefH added the bug label Jun 23, 2023
@StefH
Copy link
Collaborator

StefH commented Jun 23, 2023

@jbhelm
This will be fixed in next release.

#720

@StefH StefH closed this as completed Jun 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants