-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Create spec for lambda params with modifiers without type name #7369
Create spec for lambda params with modifiers without type name #7369
Conversation
ref
/in
/out
modifiers lambda params without type namein
/ref
/out
modifiers lambda params without type name
Can you add a line saying this is only for parenthesized lambdas? |
Speclet lgtm. @333fred for another pair of eyes. |
in
/ref
/out
modifiers lambda params without type name
An edge case includes the addition of the |
Also, in preview, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few small comments, overall this is looking good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@CyrusNajmabadi this looks good enough to go to LDM to me. Want to add it to "schedule when convenient"?
@333fred I was going to check with @MadsTorgersen @KathleenDollard first when teh right time was to bring things since we're so heads down in 12 right now. Basically, i'd bring this the next time we're open to looking for the next batch of championed constructs to take :) |
I believe that's what "schedule when convenient" there for 😉. |
Ah, i thought those were for meetings where we didn't have anything pressing, but we were still prior to the point that we were trying to decide on new features :) |
As for |
As per the list of breaking changes for C# 11, Therefore: private delegate int D(scoped int x, scoped int y);
D d = (scoped x, scoped y) => x + y; is valid and Will update the spec accordingly to reflect this change, citing the above reference. |
Is that right? Seems the breaking change only disallows declaring new types named var d = (scoped x, scoped y) => x + y; |
The example: ref scoped local; // Error Hints that all available types named |
Maybe that's an error only when there's
This test succeeds for me: [Fact]
public void Scoped()
{
var source1 = """
public class scoped { }
""";
CreateCompilation(source1).VerifyDiagnostics(
// (1,14): error CS9062: Types and aliases cannot be named 'scoped'.
// public class scoped { }
Diagnostic(ErrorCode.ERR_ScopedTypeNameDisallowed, "scoped").WithLocation(1, 14));
var comp1 = CreateCompilation(source1, parseOptions: TestOptions.Regular10).VerifyDiagnostics(
// (1,14): warning CS8981: The type name 'scoped' only contains lower-cased ascii characters. Such names may become reserved for the language.
// public class scoped { }
Diagnostic(ErrorCode.WRN_LowerCaseTypeName, "scoped").WithArguments("scoped").WithLocation(1, 14));
var comp1Ref = comp1.EmitToImageReference();
var source2 = """
var d = (scoped x) => System.Console.WriteLine(x);
d(new scoped());
""";
CompileAndVerify(source2, new[] { comp1Ref }, expectedOutput: "scoped").VerifyDiagnostics();
} |
Nice observation, with a little bit more testing, even the listed breaking change does not currently apply: Note that the above uses the Default branch which is C# 11 based on the fact that the error about naming a type This is either an undocumented decision, or an omission in the feature. We need a definite answer to how we're going to support |
if we're going to support |
…hub.com/Rekkonnect/csharplang into ref-out-lambda-params-without-type-name
Do we want to introduce a breaking change in the following example: public class C
{
public void M(scoped sc, scoped scoped scsc)
{
MSc mSc = M;
MSc mSc1 = (scoped sc, scoped scoped scsc) => { };
}
public delegate void MSc(scoped sc, scoped scoped scsc);
}
public ref struct @scoped { } I really hate how this types out anyway and I believe it would be best to introduce the breaking change by requiring the |
I would put it as a case to consider and allow the ldm to make a determination on if it's ok or not. Personally, I would take the break. |
Digging through the issues, I also discovered that #6149 is touching the subject of |
proposals/ref-out-lambda-params.md
Outdated
|
||
Parameter declarations in lambda expressions with parenthesized parameters now permit a single identifier after a modifier on the parameter. This does not apply to lambda expressions with a single parameter with omitted parentheses. | ||
|
||
For example, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For example, | |
For example, these would not be legal. |
Also, just do like the first 3 examples.
Co-Authored-By: Cyrus Najmabadi <[email protected]>
proposals/ref-out-lambda-params.md
Outdated
| 'readonly' | ||
| 'params' | ||
; | ||
``` | ||
|
||
Should the above production rule be updated to only reflect the valid combinations of modifiers, the `implicit_parenthesized_anonymous_function_parameter` rule is updated accordingly to reflect the applicable modifiers. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this note should also be removed
Creates a spec for #338
This permits the simplified declaration of lambdas with parameters with modifiers, by omitting their type name.