Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1572,7 +1572,7 @@ private void ProcessMember(

var propertyInitializer = new PropertyInitializerGenerationSpec
{
Name = property.MemberName,
Name = property.NameSpecifiedInSourceCode,
ParameterType = property.PropertyType,
MatchesConstructorParameter = matchingConstructorParameter is not null,
ParameterIndex = matchingConstructorParameter?.ParameterIndex ?? paramCount++,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,33 @@ internal partial class ModelContext : JsonSerializerContext
CompilationHelper.RunJsonSourceGenerator(compilation, logger: logger);
}

#if ROSLYN4_4_OR_GREATER && NET
[Fact]
public void InitOnlyPropertyWithReservedKeywordName_CompilesSuccessfully()
{
// Regression test for https://github.com/dotnet/runtime/issues/116507
// Verbatim identifiers like @else should be correctly handled in property initializers.

string source = """
#nullable enable
using System.Text.Json.Serialization;
public record A
{
public A? @else { get; init; }
}
[JsonSerializable(typeof(A))]
public partial class MyContext : JsonSerializerContext
{
}
""";

Compilation compilation = CompilationHelper.CreateCompilation(source);
CompilationHelper.RunJsonSourceGenerator(compilation, logger: logger);
}
#endif

[Fact]
public void RefStructPropertyWithJsonIgnore_CompilesSuccessfully()
{
Expand Down
Loading