Skip to content

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

@jbhelm

Description

@jbhelm

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!

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions