-
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New rules to validate method signature when using [UnsafeAccessor] (#657
- Loading branch information
Showing
13 changed files
with
806 additions
and
132 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# MA0145 - Signature for \[UnsafeAccessorAttribute\] method is not valid | ||
|
||
Report some cases where a method decorated with `[UnsafeAccessorAttribute]` is not valid. | ||
|
||
Note: Because some references doesn't expose their private members through Roslyn, it's not possible to validate the full signature. | ||
|
||
````c# | ||
[UnsafeAccessor(UnsafeAccessorKind.Field, Name = "dummy")] | ||
extern static ref int Demo(MyStruct a); // Not compliant as the first parameter is not by ref | ||
[UnsafeAccessor(UnsafeAccessorKind.Field, Name = "dummy")] | ||
extern static ref int Demo(ref MyStruct a); // ok | ||
```` |
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,19 @@ | ||
# MA0146 - Name must be set explicitly on local functions | ||
|
||
Local function names are mangle by the compiler, so the `Name` named constructor parameter is required | ||
|
||
````c# | ||
// non compliant | ||
void Sample() | ||
{ | ||
[UnsafeAccessor(UnsafeAccessorKind.Field)] | ||
extern static ref int _Major_(System.Version a); | ||
} | ||
|
||
// Ok | ||
void Sample() | ||
{ | ||
[UnsafeAccessor(UnsafeAccessorKind.Field, Name = "_Major")] | ||
extern static ref int _Major_(System.Version a); | ||
} | ||
```` |
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
Oops, something went wrong.