Remove support for 'ref scoped'#62788
Conversation
ffaac73 to
a0c1933
Compare
|
@dotnet/roslyn-compiler for review please. |
| @@ -541,14 +540,28 @@ internal static void CheckParameterModifiers(BaseParameterSyntax parameter, Bind | |||
| case SyntaxKind.ScopedKeyword when !parsingFunctionPointerParams: | |||
| ModifierUtils.CheckScopedModifierAvailability(parameter, modifier, diagnostics); | |||
| { | |||
| static R F1(ref R r) { Console.WriteLine(r._i); return new R(); } | ||
| static R F2(scoped ref R r) { Console.WriteLine(r._i); return new R(); } | ||
| static R F3(ref scoped R r) { Console.WriteLine(r._i); return new R(); } | ||
| static R F4(scoped ref R r) { Console.WriteLine(r._i); return new R(); } |
Consider keeping this and changing the parameter to In reply to: 1192746687 In reply to: 1192746687 In reply to: 1192746687 In reply to: 1192746687 Refers to: src/Compilers/CSharp/Test/Semantic/Semantics/RefFieldTests.cs:6692 in 95c778a. [](commit_id = 95c778a, deletion_comment = True) |
Let's test In reply to: 1192753712 In reply to: 1192753712 In reply to: 1192753712 Refers to: src/Compilers/CSharp/Test/Semantic/Semantics/RefFieldTests.cs:8741 in 95c778a. [](commit_id = 95c778a, deletion_comment = True) |
Let's test In reply to: 1192754176 In reply to: 1192754176 Refers to: src/Compilers/CSharp/Test/Semantic/Semantics/RefFieldTests.cs:8800 in 95c778a. [](commit_id = 95c778a, deletion_comment = True) |
Let's test In reply to: 1192754503 In reply to: 1192754503 Refers to: src/Compilers/CSharp/Test/Semantic/Semantics/RefFieldTests.cs:8860 in 95c778a. [](commit_id = 95c778a, deletion_comment = True) |
Change to In reply to: 1192758031 In reply to: 1192758031 Refers to: src/Compilers/CSharp/Test/Semantic/Semantics/RefFieldTests.cs:8968 in 95c778a. [](commit_id = 95c778a, deletion_comment = False) |
|
Extra blank line. In reply to: 1192759346 Refers to: src/Compilers/CSharp/Test/Semantic/Semantics/RefFieldTests.cs:12301 in 95c778a. [](commit_id = 95c778a, deletion_comment = False) |
In reply to: 1192760273 In reply to: 1192760273 Refers to: src/Compilers/CSharp/Test/Semantic/Semantics/RefFieldTests.cs:12310 in 95c778a. [](commit_id = 95c778a, deletion_comment = False) |
| static void M(R r0) | ||
| { | ||
| scoped R r1; | ||
| ref readonly scoped R r2 = ref r1; |
| scoped R r1; | ||
| ref readonly scoped R r2 = ref r1; | ||
| scoped R r1 = r0; | ||
| scoped ref R r3 = ref r0; |
|
@dotnet/roslyn-compiler for second review. Thanks |
In reply to: 1194511793 In reply to: 1194511793 Refers to: src/Compilers/CSharp/Test/Semantic/Semantics/RefFieldTests.cs:8292 in 2d8194d. [](commit_id = 2d8194d, deletion_comment = False) |
In reply to: 1194512755 Refers to: src/Compilers/CSharp/Test/Semantic/Semantics/RefFieldTests.cs:8353 in 2d8194d. [](commit_id = 2d8194d, deletion_comment = False) |
| @@ -7343,9 +7076,33 @@ public void DelegateReturnTypeScope(LanguageVersion langVersion) | |||
| "; | |||
| var comp = CreateCompilation(source, parseOptions: TestOptions.Regular.WithLanguageVersion(langVersion)); | |||
| comp.VerifyEmitDiagnostics( | |||
| // (2,14): error CS0106: The modifier 'scoped' is not valid for this item | |||
| // (2,14): error CS0246: The type or namespace name 'scoped' could not be found (are you missing a using directive or an assembly reference?) | |||
There was a problem hiding this comment.
This is an extremely bad parse. I think we should be able to do better. #Resolved
| scoped {refModifier} scoped S s3 = ref s; | ||
| }} | ||
| }}"; | ||
| var comp = CreateCompilation(source); | ||
| comp.VerifyDiagnostics( | ||
| // (6,29): error CS9048: The 'scoped' modifier can be used for refs and ref struct values only. | ||
| // (6,22): error CS0246: The type or namespace name 'scoped' could not be found (are you missing a using directive or an assembly reference?) |
There was a problem hiding this comment.
Same here. We forbid types named scoped in C# 11, right? This should be unambiguously a bad modifier, not a type name. #Resolved
333fred
left a comment
There was a problem hiding this comment.
Done review pass. I went through some of the tests, and I don't think the approach we're taking towards misplaced scoped is good. We should be able to recognize that it's a misplaced modifier and give a proper error, rather than dumping the user into a bad state. In particular, I expect people accidentally typing ref scoped instead of scoped ref to a very common failure (I still don't remember off the top of my head if it's ref readonly or readonly ref), so we need to do better for the error recovery here.
|
|
||
| ## `scoped` treated as a contextual keyword | ||
|
|
||
| ***Introduced in Visual Studio 2022 version 17.4.*** Starting in C# 11, types cannot be named `scoped`. The compiler will report an error on all such type names. To work around this, the type name and all usages must be escaped with an `@`: |
There was a problem hiding this comment.
📝 the full implementation of this break will come shortly
| @@ -1,5 +1,22 @@ | |||
| # This document lists known breaking changes in Roslyn after .NET 6 all the way to .NET 7. | |||
|
|
|||
| ## `scoped` treated as a contextual keyword | |||
There was a problem hiding this comment.
Should this be "Types cannot be named scoped" instead, assuming that captures the break, for consistency with the changes for file and required? #Resolved
| // ref struct scoped { } | ||
| Diagnostic(ErrorCode.WRN_LowerCaseTypeName, "scoped").WithArguments("scoped").WithLocation(5, 12)); | ||
| // (4,15): warning CS0219: The variable 's4' is assigned but its value is never used | ||
| // scoped scoped s4 = default; // 2 |
There was a problem hiding this comment.
Are we expecting an error on types named scoped in a future PR? Presumably what's happening is that the parser isn't treating the second scoped as a contextual keyword here? #Resolved
There was a problem hiding this comment.
I don't expect a blanket error on referencing types names scoped. I only expect that anytime we're looking for scoped, we'll prefer the keyword interpretation to the identifier interpretation.
The behavior for scoped scoped s4 is an existing issue. Filed tracking issue: #62950
| public void Local_06(LanguageVersion langVersion) | ||
| { | ||
| string source = | ||
| @"scoped.nested a; |
| string source = | ||
| @"using scoped s; | ||
| using ref scoped r; | ||
| using ref scoped r r2; |
| @"await using scoped s; | ||
| await using ref scoped; | ||
| await using ref scoped r; | ||
| await using ref scoped r r2; |
There was a problem hiding this comment.
Covered in Using_04_RefScoped? #Resolved
Fixes #62338
Relates to test plan #59194