Skip to content

Overriding Member in Base Class And Changing Nullability Breaks Rocks #271

@JasonBock

Description

@JasonBock

To reproduce:

var code =
  """
  using Rocks;

  #nullable enable

  public class Tracer
  {
    public virtual void TraceEvent(string? eventCache, string source, 
      string eventType, int id, 
      string? format, params object?[]? args)
    { }
  }

  public class SubTracer
    : Tracer
  {
    public override void TraceEvent(string eventCache, string source, 
      string eventType, int id, 
      string format, params object[] args)
    { }
  }

  public static class Test
  {
    public static void Go() => Rock.Create<SubTracer>();
  }
  """;

The issue is that Rocks thinks there are two TraceEvent() methods that can be overridden, but C# considers those to be "duplicates" and will create a CS0111 error.

Arguably, SubTracer shouldn't be changing the nullability of the parameter types (see CS8765 and CS8610 for details), but Rocks needs to handle this scenario. I'm guessing that when I look for duplicate methods (which would include indexers (maybe?)) that I do not look at the nullability decorations on the type.

Side note: when I did this in SharpLab, the overriding member is the one for the subclass, so I should do that as well in Rocks. I think I already do this, but just need to make sure this is correct.

This was found in Topshelf.Logging.TopshelfConsoleTraceListener, version 4.3.0.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions