Skip to content

Bug: Source generator doesn't escape reserved keywords in parameter names #44

@chrisbewz

Description

@chrisbewz

Hi,

Recently when consuming the package on a particular class of my code base I noticed an issue where properties named similarly to language keywords results in errors on generated code:

Consider the following sample:

[FluentApi]
public class SomeEntity
{
    /// <summary>
    /// Gets the operation to perform.
    /// </summary>
    [FluentMember(1)]
    public ConstraintOperator Operator { get; private set; }

    public static SomeEntity SomeFactory()
        => CreateSomeEntity.InitialStep().WithOperator(null);
}

When looking at the generated code you can notice that the IDE thinks you are referring to the language keyword operator raising an error ( Identifier expected):

fluentapi.g.cs:

public interface IWithOperator
{
    SomeEntity WithOperator(ConstraintOperator operator); // <-- Identifier expected
}

Usually parameters with names that conflicts with reserved keywords are prefixed with a "@" . In my particular scenario I don't have any problem in renaming the original property to avoid the errors on generated code, but maybe this could be checked by the generator itself.

Best regards,
Christian

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions