vrchat-community / UdonSharp

A compiler for compiling C# to Udon assembly
https://udonsharp.docs.vrchat.com
MIT License
462 stars 50 forks source link

[1.1.5] Extended methods with variadic arguments eat the first element #89

Open kurone-kito opened 1 year ago

kurone-kito commented 1 year ago

Describe the bug in detail:

When calling an extended method that has variadic arguments, the first element of the variadic argument disappears.

Provide steps/code to reproduce the bug:

public static void Dump(this string value, params string[] args)
{
    Debug.Log($"Dump: {value}, {string.Join(", ", args)}");
}
"a".Dump("b", "c", "d");

Expected behavior:

Expected:

Dump: a, b, c, d

Actual:

Dump: a, c, d

Additional Information:

If I pass no arguments to the above function, it should generally receive an empty array as a variadic argument, but a compile error occurs.

[UdonSharp] Assets/Scripts/Resources/ResultPreviewer.cs(50,9): System.OverflowException
  at (wrapper managed-to-native) System.Object.__icall_wrapper_ves_icall_array_new_specific(intptr,int)
  at UdonSharp.Compiler.Binder.BinderSyntaxVisitor.VisitInvocationExpression (Microsoft.CodeAnalysis.CSharp.Syntax.InvocationExpressionSyntax node) [0x0037c] in C:\Users\kurone-kito\src\my\the-mind-mirror\Packages\com.vrchat.udonsharp\Editor\Compiler\Binder\BinderSyntaxVisitor.cs:471 
  at Microsoft.CodeAnalysis.CSharp.Syntax.InvocationExpressionSyntax.Accept[TResult] (Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor`1[TResult] visitor) [0x00000] in <9c2eb1fd370b4c31a981729c5e257f1b>:0 
  at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor`1[TResult].Visit (Microsoft.CodeAnalysis.SyntaxNode node) [0x00003] in <9c2eb1fd370b4c31a981729c5e257f1b>:0 
  at UdonSharp.Compiler.Binder.BinderSyntaxVisitor.Visit (Microsoft.CodeAnalysis.SyntaxNode node) [0x00065] in C:\Users\kurone-kito\src\my\the-mind-mirror\Packages\com.vrchat.udonsharp\Editor\Compiler\Binder\BinderSyntaxVisitor.cs:51 
  at UdonSharp.Compiler.Binder.BinderSyntaxVisitor.VisitExpressionStatement (Microsoft.CodeAnalysis.CSharp.Syntax.ExpressionStatementSyntax node) [0x00001] in C:\Users\kurone-kito\src\my\the-mind-mirror\Packages\com.vrchat.udonsharp\Editor\Compiler\Binder\BinderSyntaxVisitor.cs:270 
  at Microsoft.CodeAnalysis.CSharp.Syntax.ExpressionStatementSyntax.Accept[TResult] (Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor`1[TResult] visitor) [0x00000] in <9c2eb1fd370b4c31a981729c5e257f1b>:0 
  at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor`1[TResult].Visit (Microsoft.CodeAnalysis.SyntaxNode node) [0x00003] in <9c2eb1fd370b4c31a981729c5e257f1b>:0 
  at UdonSharp.Compiler.Binder.BinderSyntaxVisitor.Visit (Microsoft.CodeAnalysis.SyntaxNode node) [0x00065] in C:\Users\kurone-kito\src\my\the-mind-mirror\Packages\com.vrchat.udonsharp\Editor\Compiler\Binder\BinderSyntaxVisitor.cs:51 
  at UdonSharp.Compiler.Binder.BinderSyntaxVisitor.VisitBlock (Microsoft.CodeAnalysis.CSharp.Syntax.BlockSyntax node) [0x00049] in C:\Users\kurone-kito\src\my\the-mind-mirror\Packages\com.vrchat.udonsharp\Editor\Compiler\Binder\BinderSyntaxVisitor.cs:261 
  at Microsoft.CodeAnalysis.CSharp.Syntax.BlockSyntax.Accept[TResult] (Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor`1[TResult] visitor) [0x00000] in <9c2eb1fd370b4c31a981729c5e257f1b>:0 
  at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor`1[TResult].Visit (Microsoft.CodeAnalysis.SyntaxNode node) [0x00003] in <9c2eb1fd370b4c31a981729c5e257f1b>:0 
  at UdonSharp.Compiler.Binder.BinderSyntaxVisitor.Visit (Microsoft.CodeAnalysis.SyntaxNode node) [0x00065] in C:\Users\kurone-kito\src\my\the-mind-mirror\Packages\com.vrchat.udonsharp\Editor\Compiler\Binder\BinderSyntaxVisitor.cs:51 
  at UdonSharp.Compiler.Symbols.MethodSymbol.Bind (UdonSharp.Compiler.Binder.BindContext context) [0x00170] in C:\Users\kurone-kito\src\my\the-mind-mirror\Packages\com.vrchat.udonsharp\Editor\Compiler\Binder\Symbols\MethodSymbol.cs:162 
  at UdonSharp.Compiler.Symbols.UdonSharpBehaviourMethodSymbol.Bind (UdonSharp.Compiler.Binder.BindContext context) [0x000b5] in C:\Users\kurone-kito\src\my\the-mind-mirror\Packages\com.vrchat.udonsharp\Editor\Compiler\Binder\Symbols\UdonSharpBehaviourMethodSymbol.cs:55 
  at UdonSharp.Compiler.Symbols.TypeSymbol.Bind (UdonSharp.Compiler.Binder.BindContext context) [0x00193] in C:\Users\kurone-kito\src\my\the-mind-mirror\Packages\com.vrchat.udonsharp\Editor\Compiler\Binder\Symbols\TypeSymbol.cs:137 
  at UdonSharp.Compiler.Binder.BindContext.Bind () [0x0001b] in C:\Users\kurone-kito\src\my\the-mind-mirror\Packages\com.vrchat.udonsharp\Editor\Compiler\Binder\BindContext.cs:35 
  at UdonSharp.Compiler.UdonSharpCompilerV1+<>c__DisplayClass22_0.<BindAllPrograms>b__0 (System.ValueTuple`2[T1,T2] rootTypeSymbol) [0x00030] in C:\Users\kurone-kito\src\my\the-mind-mirror\Packages\com.vrchat.udonsharp\Editor\Compiler\UdonSharpCompilerV1.cs:618