Skip to content

Commit

Permalink
Suppress an assert when an indexer is declared, but DefaultMemberName…
Browse files Browse the repository at this point in the history
…Attribute is missing.

Fixes dotnet#75032.
  • Loading branch information
AlekseyTs committed Sep 12, 2024
1 parent 64ba034 commit 1c90a61
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1713,7 +1713,7 @@ internal override void AddSynthesizedAttributes(PEModuleBuilder moduleBuilder, r

AddSynthesizedAttribute(ref attributes, compilation.TrySynthesizeAttribute(
WellKnownMember.System_Reflection_DefaultMemberAttribute__ctor,
ImmutableArray.Create(defaultMemberNameConstant)));
ImmutableArray.Create(defaultMemberNameConstant), isOptionalUse: true));
}

if (this.declaration.Declarations.All(d => d.IsSimpleProgram))
Expand Down
16 changes: 16 additions & 0 deletions src/Compilers/CSharp/Test/Emit/CodeGen/IndexerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1185,5 +1185,21 @@ static void Main()
}

#endregion Lowering

[Fact]
[WorkItem("https://github.com/dotnet/roslyn/issues/75032")]
public void MissingDefaultMemberAttribute()
{
var text = @"
interface I1
{
I1 this[I1 args] { get; }
}
";
var comp = CreateCompilation(text);
comp.MakeMemberMissing(WellKnownMember.System_Reflection_DefaultMemberAttribute__ctor);

CompileAndVerify(comp).VerifyDiagnostics();
}
}
}

0 comments on commit 1c90a61

Please sign in to comment.