Skip to content

scoped is Added to params #328

@JasonBock

Description

@JasonBock

To Reproduce

Run this in the test project:

using Rocks;
using System;

[assembly: Rock(typeof(ParamMethods), BuildType.Create | BuildType.Make)]

public class ParamMethods
{
  public virtual void Do(params string[] args) { }
  public virtual void DoSpan(params ReadOnlySpan<string> args) { }
}

Expected behavior
Mock code is built and compiles.

Actual behavior
Errors occur:

    Diagnostics:
    // Rocks\Rocks.RockGenerator\ParamMethods_Rock_Create.g.cs(18,84): error CS0246: The type or namespace name 'scoped' could not be found (are you missing a using directive or an assembly reference?)
    DiagnosticResult.CompilerError("CS0246").WithSpan("Rocks\Rocks.RockGenerator\ParamMethods_Rock_Create.g.cs", 18, 84, 18, 90).WithArguments("scoped"),
    // Rocks\Rocks.RockGenerator\ParamMethods_Rock_Create.g.cs(18,91): error CS1001: Identifier expected
    DiagnosticResult.CompilerError("CS1001").WithSpan("Rocks\Rocks.RockGenerator\ParamMethods_Rock_Create.g.cs", 18, 91, 18, 97),
    // Rocks\Rocks.RockGenerator\ParamMethods_Rock_Create.g.cs(18,91): error CS1003: Syntax error, ',' expected
    DiagnosticResult.CompilerError("CS1003").WithSpan("Rocks\Rocks.RockGenerator\ParamMethods_Rock_Create.g.cs", 18, 91, 18, 97).WithArguments(","),
    // Rocks\Rocks.RockGenerator\ParamMethods_Rock_Create.g.cs(187,31): error CS0246: The type or namespace name 'scoped' could not be found (are you missing a using directive or an assembly reference?)
    DiagnosticResult.CompilerError("CS0246").WithSpan("Rocks\Rocks.RockGenerator\ParamMethods_Rock_Create.g.cs", 187, 31, 187, 37).WithArguments("scoped"),
    // Rocks\Rocks.RockGenerator\ParamMethods_Rock_Create.g.cs(187,38): error CS1001: Identifier expected
    DiagnosticResult.CompilerError("CS1001").WithSpan("Rocks\Rocks.RockGenerator\ParamMethods_Rock_Create.g.cs", 187, 38, 187, 44),
    // Rocks\Rocks.RockGenerator\ParamMethods_Rock_Create.g.cs(187,38): error CS1003: Syntax error, ',' expected
    DiagnosticResult.CompilerError("CS1003").WithSpan("Rocks\Rocks.RockGenerator\ParamMethods_Rock_Create.g.cs", 187, 38, 187, 44).WithArguments(","),
    // Rocks\Rocks.RockGenerator\ParamMethods_Rock_Create.g.cs(199,33): error CS1503: Argument 1: cannot convert from 'System.ReadOnlySpan<string>' to 'scoped'
    DiagnosticResult.CompilerError("CS1503").WithSpan("Rocks\Rocks.RockGenerator\ParamMethods_Rock_Create.g.cs", 199, 33, 199, 38).WithArguments("1", "System.ReadOnlySpan<string>", "scoped"),
    // Rocks\Rocks.RockGenerator\ParamMethods_Rock_Make.g.cs(40,31): error CS0246: The type or namespace name 'scoped' could not be found (are you missing a using directive or an assembly reference?)
    DiagnosticResult.CompilerError("CS0246").WithSpan("Rocks\Rocks.RockGenerator\ParamMethods_Rock_Make.g.cs", 40, 31, 40, 37).WithArguments("scoped"),
    // Rocks\Rocks.RockGenerator\ParamMethods_Rock_Make.g.cs(40,38): error CS1001: Identifier expected
    DiagnosticResult.CompilerError("CS1001").WithSpan("Rocks\Rocks.RockGenerator\ParamMethods_Rock_Make.g.cs", 40, 38, 40, 44),
    // Rocks\Rocks.RockGenerator\ParamMethods_Rock_Make.g.cs(40,38): error CS1003: Syntax error, ',' expected
    DiagnosticResult.CompilerError("CS1003").WithSpan("Rocks\Rocks.RockGenerator\ParamMethods_Rock_Make.g.cs", 40, 38, 40, 44).WithArguments(","),

Additional context
What's happening is that params have been updated in C# 13 that you can use things like ReadOnlySpan<>. Right now, Rocks thinks it needs to add scoped to the parameter in DoSpan(), but that should not be done if it's a params.

This was found on many types, System.IO.StreamWriter being one of them.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions