-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Make extracted parameters non-nullable when possible. #76386
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
Changes from 5 commits
8eeb3e2
cf82179
d9308fa
1a4b3ff
851c621
6a6051c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| using System.Security; | ||
CyrusNajmabadi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| using System.Threading.Tasks; | ||
| using Microsoft.CodeAnalysis.CodeRefactorings; | ||
| using Microsoft.CodeAnalysis.CodeRefactorings.ExtractMethod; | ||
|
|
@@ -11,6 +12,7 @@ | |
| using Microsoft.CodeAnalysis.CSharp.Test.Utilities; | ||
| using Microsoft.CodeAnalysis.Editor.UnitTests.CodeActions; | ||
| using Microsoft.CodeAnalysis.Test.Utilities; | ||
| using Microsoft.CodeAnalysis.Testing; | ||
| using Roslyn.Test.Utilities; | ||
| using Xunit; | ||
|
|
||
|
|
@@ -3302,7 +3304,7 @@ class C | |
| { | ||
| public string? M() | ||
| { | ||
| string? x = {|Rename:NewMethod|}(); | ||
| string x = {|Rename:NewMethod|}(); | ||
|
|
||
| return x; | ||
| } | ||
|
|
@@ -5867,6 +5869,101 @@ public async Task Goo() | |
| """, | ||
| options: ImplicitTypeEverywhere()); | ||
|
|
||
| [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/61555")] | ||
| public async Task TestKnownNotNullParameter() | ||
| => await new VerifyCS.Test | ||
| { | ||
| TestCode = """ | ||
| #nullable enable | ||
|
|
||
| public class C | ||
| { | ||
| public void M(C? c) | ||
| { | ||
| if (c == null) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| [|c.ToString();|] | ||
| } | ||
| } | ||
| """, | ||
| FixedCode = """ | ||
| #nullable enable | ||
|
|
||
| public class C | ||
| { | ||
| public void M(C? c) | ||
| { | ||
| if (c == null) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| NewMethod(c); | ||
| } | ||
|
|
||
| private static void NewMethod(C c) | ||
| { | ||
| c.ToString(); | ||
| } | ||
| } | ||
| """, | ||
| LanguageVersion = LanguageVersion.CSharp13, | ||
| ReferenceAssemblies = ReferenceAssemblies.Net.Net90, | ||
| }.RunAsync(); | ||
|
|
||
| [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/61555")] | ||
| public async Task TestKnownNotNullParameter_AssignedNull() | ||
| => await new VerifyCS.Test | ||
| { | ||
| TestCode = """ | ||
| #nullable enable | ||
|
|
||
| public class C | ||
| { | ||
| public void M(C? c) | ||
| { | ||
| if (c == null) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| [|c.ToString(); | ||
| c = null; | ||
| c?.ToString();|] | ||
| } | ||
| } | ||
| """, | ||
| FixedCode = """ | ||
| #nullable enable | ||
|
|
||
| public class C | ||
| { | ||
| public void M(C? c) | ||
| { | ||
| if (c == null) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| c = NewMethod(c); | ||
| } | ||
|
|
||
| private static C? NewMethod(C? c) | ||
| { | ||
| {|CS8602:c|}.ToString(); | ||
| c = null; | ||
| c?.ToString(); | ||
| return c; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why return
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unclear :-). I'll have to debug through to see what's going on (note, this is unrelated to this pr). |
||
| } | ||
| } | ||
| """, | ||
| LanguageVersion = LanguageVersion.CSharp13, | ||
| ReferenceAssemblies = ReferenceAssemblies.Net.Net90, | ||
| }.RunAsync(); | ||
|
|
||
| [Theory, CombinatorialData, WorkItem("https://github.com/dotnet/roslyn/issues/67017")] | ||
| public async Task TestPrimaryConstructorBaseList(bool withBody) | ||
| { | ||
|
|
||
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.
Was this intentional? It doesn't look to me like anything uses something from System.Security.
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.
nope!