Doraku / DefaultEcs.Analyzer

Roslyn analyzers for DefaultEcs users.
MIT No Attribution
13 stars 1 forks source link

CreateEntityContainer with custom predicate is not nullable-compliant #7

Closed Helco closed 2 years ago

Helco commented 2 years ago

In a context where nullable references are enabled and set to trigger errors a class that provides a custom predicate causes such an error in the generated CreateEntityContainer method. I guess instead of the as operator one should use an exception-throwing cast. An exception would be thrown in the null-case anyway.

Example system:

public partial class Test : AEntitySetSystem<float>
    {
        public Test(World world) : base(world) { }

        [WithPredicate]
        private bool Filter(in int _) => false;

        [Update]
        private void Update(float state, in int _) { }
    }

Generated CreateEntityContainer method:

        [CompilerGenerated]
        private static EntitySet CreateEntityContainer(object sender, World world) => world
            .GetEntities()
            .With<int>()
            .With<int>((sender as Test).Filter) // CS8602: Dereference of a possibly null reference.
            .AsSet();