Cysharp / MasterMemory

Embedded Typed Readonly In-Memory Document Database for .NET and Unity.
MIT License
1.52k stars 110 forks source link

Bug: dotnet-mmgen throws a NullReferenceException when processing a [SecondaryKey] with a non-literal argument #72

Closed JesseTG closed 2 years ago

JesseTG commented 3 years ago

If you run dotnet-mmgen on this class...

using MasterMemory;
using MessagePack;

namespace CorundumGames
{
    [MessagePackObject, MemoryTable("BugTable")]
    public sealed class BugEntry
    {
        private const int SecondaryKeyIndex = 0;

        [Key(0)]
        [PrimaryKey]
        public int Primary { get; }

        [Key(1)]
        [SecondaryKey(SecondaryKeyIndex)]
        public string Secondary { get; }
    }
}

...then it will fail with an error message that looks something like this:

Fail in console app running on Program.Execute
System.NullReferenceException: Object reference not set to an instance of an object.
   at MasterMemory.GeneratorCore.CodeGenerator.ExtractPropertyAttribute(PropertyDeclarationSyntax property) in /home/runner/work/MasterMemory/MasterMemory/src/MasterMemor
y.GeneratorCore/CodeGenerator.cs:line 205
   at MasterMemory.GeneratorCore.CodeGenerator.<CreateGenerationContext>b__4_5(PropertyDeclarationSyntax x) in /home/runner/work/MasterMemory/MasterMemory/src/MasterMemor
y.GeneratorCore/CodeGenerator.cs:line 165
   at System.Linq.Enumerable.SelectEnumerableIterator`2.ToArray()
   at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
   at MasterMemory.GeneratorCore.CodeGenerator.CreateGenerationContext(String filePath)+MoveNext()
   at System.Collections.Generic.List`1.InsertRange(Int32 index, IEnumerable`1 collection)
   at MasterMemory.GeneratorCore.CodeGenerator.GenerateFile(String usingNamespace, String inputDirectory, String outputDirectory, String prefixClassName, Boolean addImmut
ableConstructor, Boolean throwIfKeyNotFound, Boolean forceOverwrite, Action`1 logger) in /home/runner/work/MasterMemory/MasterMemory/src/MasterMemory.GeneratorCore/CodeGe
nerator.cs:line 30
   at MasterMemory.Generator.Program.Execute(String inputDirectory, String outputDirectory, String usingNamespace, String prefixClassName, Boolean addImmutableConstructor
, Boolean returnNullIfKeyNotFound, Boolean forceOverwrite) in /home/runner/work/MasterMemory/MasterMemory/src/MasterMemory.Generator/Program.cs:line 31

However, running it on this (look at the [SecondaryKey])...

using MasterMemory;
using MessagePack;

namespace CorundumGames
{
    [MessagePackObject, MemoryTable("BugTable")]
    public sealed class BugEntry
    {
        [Key(0)]
        [PrimaryKey]
        public int Primary { get; }

        [Key(1)]
        [SecondaryKey(0)]
        public string Secondary { get; }
    }
}

...works as expected.

github-actions[bot] commented 3 years ago

This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 7 days.

neuecc commented 3 years ago

Thanks for the report. This issues should check.

github-actions[bot] commented 2 years ago

This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 7 days.

github-actions[bot] commented 2 years ago

This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 7 days.