-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Check Locations length before accessing #87659
Conversation
Tagging subscribers to this area: @agocke, @sbomer, @vitek-karas Issue DetailsFixes an I'm also adding checks in the other places this analyzer accesses
|
|
||
foreach (var parameter in method.Parameters) { | ||
foreach (var diagnostic in ProcessGenericParameters (parameter.Type, parameter.Locations[0])) | ||
context.ReportDiagnostic (diagnostic); | ||
if (parameter.Locations.Length > 0) { |
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 check is the only one necessary to fix the reported issue.
src/tools/illink/src/ILLink.RoslynAnalyzer/DynamicallyAccessedMembersAnalyzer.cs
Outdated
Show resolved
Hide resolved
Wasm tests are still failing with the same error: We use the latest 8.0 sdk to run the tests, so we would need to wait for this change to show up in a new sdk. |
src/tools/illink/src/ILLink.RoslynAnalyzer/DynamicallyAccessedMembersAnalyzer.cs
Outdated
Show resolved
Hide resolved
src/tools/illink/src/ILLink.RoslynAnalyzer/DynamicallyAccessedMembersAnalyzer.cs
Outdated
Show resolved
Hide resolved
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.
LGTM, thanks!
public static async Task VerifyAnalyzerAsync (string src, (string, string)[]? analyzerOptions = null, IEnumerable<MetadataReference>? additionalReferences = null, params DiagnosticResult[] expected) | ||
public static async Task VerifyAnalyzerAsync ( | ||
string src, | ||
bool consoleApplication, |
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.
Nit: Make it false
by default to avoid changing so many lines - and also to simplify the most common usage.
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.
I couldn't find a good way to make it optional - the second argument seems to be always treated as part of the params[]
args: https://sharplab.io/#v2:C4LgTgrgdgNAJiA1AHwMIDoCyAKARACwFMAbYge1xgAIBGamgSgG4BYAKHYAEAmK1KgN7sqIqpwDMYmgDYxAFio5ONAAxUAztQBGZMsSpaqAXioAzAIbF1hagAdzYcwFt1VAJZRgAbQC6VBwDm6gyCAL7soUA===.
Fixes an
IndexOutOfRangeException
thrown by the analyzer when analyzing method parameters for the implicitly generated Main method when using top-level statements. These method parameters don't have location info because they are not in user code.I'm also adding checks in the other places this analyzer accesses
Locations[0]
, to be safe. But only one of these accesses was causing the crash reported in #87647. @vitek-karas @agocke please let me know if you have opinions on whether we should do a more targeted fix.Fixes #87647