You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I experimented with the new extension feature and found a possible bug. When I am in extension block like this extension(string s) { … } and inside I create a method like this public void Print([CallerArgumentExpression("s")] string caller = "") { … } the argument caller is not set to the argument expression. Like if I call "FooBar".Print(), the value is not ""FooBar"".
the result would be empty string, instead of "fooBar".
So maybe this behaviour for extensions is deliberate, so that it behaves like it was an instance methods.
But on the other hand, extension methods didn’t behave that way.
And also maybe, [CallerArgumentExpression("this")] should work in instance methods as well.
This is about 2 C# language features (caller argument expression and the new extensions syntax), so I'll transfer it to the roslyn repo for analysis. Thanks for reporting!
Describe the bug
I experimented with the new extension feature and found a possible bug. When I am in extension block like this
extension(string s) { … }
and inside I create a method like thispublic void Print([CallerArgumentExpression("s")] string caller = "") { … }
the argument caller is not set to the argument expression. Like if I call"FooBar".Print()
, the value is not ""FooBar"".To Reproduce
Install dotnet sdk preview 10.0.100-preview.3.25201.16.
compile the following Code, into a ConsoleApp:
If you run it, the output will be:
But the method
Print
andPrint2
are just different notations for the same thing (syntactic sugar), so should produce the same output.Exceptions (if any)
No exceptions.
Further technical details
dotnet --info
:The text was updated successfully, but these errors were encountered: