Repository navigation
[Compiler] Fix IndexOutOfRangeException when analyzers and .editorconfig are used - #2098
Conversation
…fig are used
UpdateAnalyzerConfigOptionsProvider indexes sourceFileAnalyzerConfigOptions
with the position of each tree in compilation.SyntaxTrees. X# adds one extra
entry ("generatedcode.prg") for compiler generated code, but a compilation can
contain two generated trees: the tree from XSharpLanguageParser.ProcessTrees
(literal symbols, PSZ literals, partial types) and the default tree from
AddXSharpSyntaxTree (runtime dialects). With /analyzer and /analyzerconfig
xsc then crashed with an unhandled IndexOutOfRangeException, which MSBuild
reports as MSB4181 "Xsc returned false but did not log an error".
Trees beyond the end of the array now use the last entry, the placeholder for
generated code.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Hansjoerg, |
|
@RobertvanderHulst I have created a new PR |
|
@hpetriffer Which runtime tests are failing? Since the list is long, just please name a few so I get an idea. Some weeks ago I had made sure that all tests pass, might have missed something. |
|
@cpyrgas 19 of the 22 never get as far as running, because they don't compile. The summary still says Why most of them fail silently: the runner (
What would fix most of them: updating the runtime DLLs in |
…d in #2098 (#2099) C990 compiles VO code with a literal symbol together with /analyzer and /analyzerconfig. That combination produced two compiler generated syntax trees and crashed xsc with an IndexOutOfRangeException before #2098. The test needs an analyzer that xsc can load, so this adds a small no-op analyzer (src/CompilerTests/Analyzers/XSharpTestAnalyzer) that is built against the XSharp.CodeAnalysis.dll of the tested compiler. runtests.cmd builds it into Bin\Analyzers before the tests run. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks @hpetriffer , I have adjusted a couple tests. But for me the tests C703, C901 and R832 still do not pass. Also a few other tests still fail with the updated runtime, I think they were broken after some other fixes in the last weeks. Since it's work in progress, I did not update the runtime dlls yet, will do that when they are fixed. |
With
/analyzerand/analyzerconfig,xsccrashes with an unhandledIndexOutOfRangeExceptionfor VO-dialect code (and the other runtime dialects) that contains a literal symbol, a PSZ literal or a partial type. MSBuild only reports:The real error is only in the task output:
Found while building a large VO library that referenced an analyzer NuGet package; the repo-level
.editorconfigmade MSBuild pass/analyzerconfig.SkipAnalyzers=truedoes not remove aPackageReferenceanalyzer.Cause
UpdateAnalyzerConfigOptionsProviderreadssourceFileAnalyzerConfigOptions[i]for the i-th tree incompilation.SyntaxTrees. The array has one entry per source file plus one placeholder,generatedcode.prg, added inCommonCompiler.RunCore(0f8a184, 2024). A compilation can contain two generated trees:XSharpLanguageParser.ProcessTrees(CSharpCompiler.CreateCompilation), created when there are literal symbols, PSZ literals or partial types;AddXSharpSyntaxTree(CSharpCompilation.AddSyntaxTrees), added for the runtime dialects.With both, there is one tree more than array entries. The code only runs when at least one analyzer or generator is loaded and at least one analyzer config file is passed.
Fix
Inside
#if XSHARP, a tree beyond the end of the array uses the last entry, thegeneratedcode.prgplaceholder. All generated trees get the same.editorconfigoptions, however many there are.CompilerSyntaxTreeOptionsProvideris not affected: it receives the trees before the default tree is added, and the placeholder covers theProcessTreestree.Repro
The analyzer has to be built against
XSharp.CodeAnalysis.dll; Roslyn analyzers such as the WinForms ones are not loaded byxsc. A no-opDiagnosticAnalyzerwith[DiagnosticAnalyzer("X#")]is enough. Without the#HELLOline it compiles, because only the default tree is generated.There is no analyzer in the repo, and the compiler test runner cannot pass one without adding a test analyzer project and a build step to
runtests.cmd. I built that locally to verify the fix but did not include it here.Testing
Based on
dev@7627782269. Release build viasrc\buildcompiler.cmd Release(0 warnings, 0 errors), tests viaRunCompilertests.cmd.IndexOutOfRangeExceptionHELLOIndexOutOfRangeException-532462766The 25 failing runtime tests fail on
devalready; the set of failing test IDs is identical before and after.No existing issue found (searched for
IndexOutOfRangeException analyzer,UpdateAnalyzerConfigOptionsProvider,editorconfig analyzer crash).🤖 Generated with Claude Code