M31.FluentAPI icon indicating copy to clipboard operation
M31.FluentAPI copied to clipboard

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

Open chrisbewz opened this issue 4 months ago • 1 comments

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

chrisbewz avatar Oct 06 '25 16:10 chrisbewz

Hi @chrisbewz,

Good catch, thank you for reporting this!

I’ll work on a fix soon.

Best regards, Kevin

m31coding avatar Oct 07 '25 09:10 m31coding