Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Breaking change and spec violation for code using underscore to refer to single lambda parameter #46117

Closed
jnm2 opened this issue Jul 18, 2020 · 3 comments
Assignees

Comments

@jnm2
Copy link
Contributor

jnm2 commented Jul 18, 2020

Version Used: 16.6.4, SharpLab shows it on master

There's a lot of code out there like this:

using System.Linq;

class C
{
    void M()
    {
        // ❌ CS0103 The name '_' does not exist in the current context
        //                                ↓
        Enumerable.Range(0, 1).Select(_ = _.ToString());
    }
}

This doesn't follow the spec in https://github.com/dotnet/csharplang/blob/master/proposals/lambda-discard-parameters.md#detailed-design:

Note: if a single parameter is named _ then it is a regular parameter for backwards compatibility reasons.

@Joe4evr
Copy link

Joe4evr commented Jul 18, 2020

CC: @jcouv This should be covered by the test plan #38820

  • that a single _ is not a discard parameter (ie. is in scope and can be read from) (see DiscardParameters_NotADiscardWhenSingleUnderscore)

@jcouv
Copy link
Member

jcouv commented Jul 20, 2020

I'm confused. There is no lambda in the example. Did you mean .Select(_ => _.ToString()) with a =>?

@jcouv jcouv self-assigned this Jul 20, 2020
@jnm2
Copy link
Contributor Author

jnm2 commented Jul 20, 2020

Oh my, I'm so sorry! Wow 😆

@jnm2 jnm2 closed this as completed Jul 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants