HaxeFoundation / haxe

Haxe - The Cross-Platform Toolkit
https://haxe.org
6.21k stars 657 forks source link

[cs] The parameter name '_' is a duplicate #10332

Closed NQNStudios closed 10 months ago

NQNStudios commented 3 years ago

I've reproduced a bug that causes an error when using the tink_core macro library with C#.

Main.hx:

package template;

import template.Other;

class Main {
    static function main() {
        var other = new Other<String>();
        var func = Reflect.field(other, "func");
        func("foo", "bar");
    }
}

Other.hx:

package template;

class Other<T> {
    public function new() {}
    public function func(_, _) {

    }
}

Generates Other.cs (abridged to show relevant lines):

    public class Other<T> : global::haxe.lang.HxObject, global::template.Other {
        public virtual void func(object _, object _1) {
        }
        }

    [global::haxe.lang.GenericInterface(typeof(global::template.Other<object>))]
    public interface Other : global::haxe.lang.IHxObject, global::haxe.lang.IGenericObject {
        void func(object _, object _);
    }

The parameter name _ is disambiguated in the first generated class, avoiding a C# compiler error, but the same is not done for the method generated on the interface.

The resulting C# error is src\template\Other.cs(100,30): error CS0100: The parameter name '_' is a duplicate .

Other must be a generic class, AND Reflect.field must be called on func, to reproduce this error.

I'm wondering if this would be a good first issue for me to get started contributing some maintenance to the C# target.

RealyUniqueName commented 3 years ago

This issue could be relatively easy to fix indeed. The difficult part may be to find the place where this should be fixed. C# and Java generators share quite complex codebase. It usually takes time to figure out program flow.