-
Notifications
You must be signed in to change notification settings - Fork 128
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
Fix delegate conversion on analyzers #1964
Changes from all commits
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 |
---|---|---|
|
@@ -352,5 +352,52 @@ public void M() | |
|
||
return VerifyRequiresAssemblyFilesAnalyzer (src); | ||
} | ||
|
||
[Fact] | ||
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. Same with the tests. Can we start to share stuff here? 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. I open #1986 to track the refactoring work in a separate PR since I think it would have a lot of feedback. |
||
public Task LazyDelegateWithRequiresAssemblyFiles () | ||
{ | ||
const string src = @" | ||
using System; | ||
using System.Diagnostics.CodeAnalysis; | ||
class C | ||
{ | ||
public static Lazy<C> _default = new Lazy<C>(InitC); | ||
public static C Default => _default.Value; | ||
|
||
[RequiresAssemblyFiles] | ||
public static C InitC() { | ||
C cObject = new C(); | ||
return cObject; | ||
} | ||
}"; | ||
|
||
return VerifyRequiresAssemblyFilesAnalyzer (src, | ||
// (6,50): warning IL3002: Using member 'C.InitC()' which has 'RequiresAssemblyFilesAttribute' can break functionality when embedded in a single-file app. | ||
VerifyCS.Diagnostic (RequiresAssemblyFilesAnalyzer.IL3002).WithSpan (6, 50, 6, 55).WithArguments ("C.InitC()", "", "")); | ||
} | ||
|
||
[Fact] | ||
public Task ActionDelegateWithRequiresAssemblyFiles () | ||
{ | ||
const string src = @" | ||
using System; | ||
using System.Diagnostics.CodeAnalysis; | ||
class C | ||
{ | ||
[RequiresAssemblyFiles] | ||
public static void M1() { } | ||
public static void M2() | ||
{ | ||
Action a = M1; | ||
Action b = () => M1(); | ||
} | ||
}"; | ||
|
||
return VerifyRequiresAssemblyFilesAnalyzer (src, | ||
// (10,20): warning IL3002: Using member 'C.M1()' which has 'RequiresAssemblyFilesAttribute' can break functionality when embedded in a single-file app. | ||
VerifyCS.Diagnostic (RequiresAssemblyFilesAnalyzer.IL3002).WithSpan (10, 20, 10, 22).WithArguments ("C.M1()", "", ""), | ||
// (11,26): warning IL3002: Using member 'C.M1()' which has 'RequiresAssemblyFilesAttribute' can break functionality when embedded in a single-file app. | ||
VerifyCS.Diagnostic (RequiresAssemblyFilesAnalyzer.IL3002).WithSpan (11, 26, 11, 30).WithArguments ("C.M1()", "", "")); | ||
} | ||
} | ||
} |
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.
This diff makes me think we need to share more between the two analyzers. They look like they're doing pretty much exactly the stuff.