Skip to content

Code is not correctly generated when using directives are wrapped with #if and #endif #109

Open
@Haruma-K

Description

@Haruma-K

We encountered an issue where generated code results in compilation errors when using directives are conditionally included using #if / #endif.

Here is a minimal reproducible example:

#if !MASTER_MEMORY_DISABLED
using MasterMemory;
using MessagePack;
#endif

namespace Example1
{
#if !MASTER_MEMORY_DISABLED
    [MemoryTable("person")]
    [MessagePackObject(true)]
#endif
    public record Person
    {
#if !MASTER_MEMORY_DISABLED
        [PrimaryKey] 
#endif
        public int Id { get; set; }
    }
}

When using this pattern, the generated code causes compilation errors with the following messages:

MasterMemory.SourceGenerator/MasterMemory.SourceGenerator.MasterMemoryGenerator/MasterMemory.DatabaseBuilder.g.cs(29,2): error CS1027: #endif directive expected
MasterMemory.SourceGenerator/MasterMemory.SourceGenerator.MasterMemoryGenerator/MasterMemory.ImmutableBuilder.g.cs(64,2): error CS1027: #endif directive expected
MasterMemory.SourceGenerator/MasterMemory.SourceGenerator.MasterMemoryGenerator/MasterMemory.MemoryDatabase.g.cs(129,2): error CS1027: #endif directive expected
MasterMemory.SourceGenerator/MasterMemory.SourceGenerator.MasterMemoryGenerator/MasterMemory.MasterMemoryResolver.g.cs(70,2): error CS1027: #endif directive expected
MasterMemory.SourceGenerator/MasterMemory.SourceGenerator.MasterMemoryGenerator/MasterMemory.PersonTable.g.cs(105,2): error CS1027: #endif directive expected

We’d appreciate it if you could take a look and consider supporting this pattern.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions