Skip to content

Virtual Members Using the new Keyword Breaks Base Invocations #334

@JasonBock

Description

@JasonBock

To Reproduce

#nullable enable

using Rocks;
using System;
		
[assembly: Rock(typeof(NewNameUsage), BuildType.Create)]

public class NewNameUsage
{
  public virtual void Work(string @new) { }
}

Expected behavior
The mock is created with no issues.

Actual behavior
Errors occur:

Error - Id: CS1003, Description: Rocks\Rocks.RockGenerator\NewNameUsage_Rock_Create.g.cs(146,18): error CS1003: Syntax error, ',' expected
Error - Id: CS1003, Description: Rocks\Rocks.RockGenerator\NewNameUsage_Rock_Create.g.cs(146,20): error CS1003: Syntax error, ',' expected
Error - Id: CS1526, Description: Rocks\Rocks.RockGenerator\NewNameUsage_Rock_Create.g.cs(146,18): error CS1526: A new expression requires an argument list or (), [], or {} after type

Additional context
The problem is that the method's parameter uses new for the name and is virtual. Within the override, Rocks puts in a call to the base class method, but it'll do this:

base.Work(new: @new);

What it should do is:

base.Work(@new: @new);

In general, any base invocation should always put @ in front of the parameter name.

This was found on Microsoft.EntityFrameworkCore.Query.Internal.ExpressionTreeFuncletizer

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions