-
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Supporting C# 8 Nullable Reference Type attributes (#229)
* Supporting C# 8 Nullable Reference Type attributes - Method parameters and return values that use nullable reference types don't have null guards inserted Implements #203 * Add documentation
- Loading branch information
1 parent
eed6f12
commit 28a0c73
Showing
6 changed files
with
118 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
#nullable enable | ||
public class NullableReferenceTypeClass | ||
{ | ||
/* | ||
public void SomeMethod(string nonNullArg, [Nullable(2)] string nullArg) | ||
{ | ||
Console.WriteLine(nonNullArg); | ||
} | ||
*/ | ||
public void SomeMethod(string nonNullArg, string? nullArg) | ||
{ | ||
Console.WriteLine(nonNullArg); | ||
} | ||
|
||
public string MethodWithReturnValue(bool returnNull) | ||
{ | ||
#pragma warning disable CS8603 // Possible null reference return. | ||
return returnNull ? null : ""; | ||
#pragma warning restore CS8603 // Possible null reference return. | ||
} | ||
|
||
/* | ||
[NullableContext(2)] | ||
public string MethodAllowsNullReturnValue() | ||
{ | ||
return (string) null; | ||
} | ||
*/ | ||
public string? MethodAllowsNullReturnValue() | ||
{ | ||
return null; | ||
} | ||
} | ||
#nullable disable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
Tests/RewritingMethods.RequiresNonNullArgumentWhenNullableReferenceTypeNotUsed.verified.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[NullGuard] nonNullArg is null. | ||
Parameter name: nonNullArg |
1 change: 1 addition & 0 deletions
1
...tingMethods.RequiresNonNullMethodReturnValueWhenNullableReferenceTypeNotUsed.verified.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[NullGuard] Return value of method 'System.String NullableReferenceTypeClass::MethodWithReturnValue(System.Boolean)' is null. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters