Skip to content

Fix light-up fallbacks for base syntax types - #4357

Merged
AArnott merged 2 commits into
masterfrom
aarnott-probable-invention
Oct 20, 2026
Merged

AArnott merged 2 commits into
masterfrom
aarnott-probable-invention

Conversation

@AArnott

@AArnott AArnott commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

Older Roslyn hosts lack syntax base types and members introduced in later compilers, leaving several light-up fallbacks incomplete.

Fixes #3258

Changes

  • Fall back from BaseParameterSyntax to ParameterSyntax on older hosts.
  • Recognize both expressions and patterns when ExpressionOrPatternSyntax is unavailable, while rejecting unrelated nodes.
  • Dispatch member attribute and modifier operations to derived implementations when the base APIs are unavailable. Select fallback delegates once during static initialization, keeping reflection centralized and modern access paths unchanged.
  • Regenerate wrappers and document the compatibility requirements.

Validation

The initial regression tests failed against unchanged product code: parameter and expression recognition failed, and member updates threw NotSupportedException. Added coverage for reads, updates, conversions, null handling, unsupported members, and function pointer parameters.

All light-up suites pass for C# 6 through C# 15 on both net10.0 and net472. Builds completed with zero warnings, and a non-incremental regeneration preserved the generated output.

Performance

No analyzer registrations, semantic-model work, or tree walks changed. Member access retains its existing delegates on modern hosts; older hosts use syntax-type dispatch without per-access reflection.

Support parameter and expression/pattern wrappers on older Roslyn hosts, and dispatch member attributes and modifiers to derived APIs when base members are unavailable. Preserve modern accessors and cover compatibility across the compiler matrix.

Fixes #3258

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@AArnott
AArnott marked this pull request as ready for review October 20, 2026 00:43
Copilot AI balanced review requested due to automatic review settings October 20, 2026 00:43

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Two regression suites are excluded from compiler-version inheritance, leaving their checks absent from later Roslyn hosts.

2 open issues
What changed in this PR

Fixes older-Roslyn compatibility in StyleCop’s syntax light-up layer, addressing #3258.

Changes:

  • Adds parameter and expression-or-pattern fallbacks.
  • Dispatches member operations to derived implementations when base APIs are unavailable.
  • Adds regression tests, regenerates wrappers, and documents compatibility requirements.
File Description
tools/​StyleCop.Analyzers.CodeGeneration/​SyntaxLightupGenerator.cs Generates fallback-aware wrappers.
test/​StyleCop.Analyzers.Test/​Lightup/​SyntaxWrapperTests.cs Tests parameter and expression fallbacks.
test/​StyleCop.Analyzers.Test/​Lightup/​SyntaxWrapperHelperUnitTests.cs Checks parameter fallback type resolution.
test/​StyleCop.Analyzers.Test/​Lightup/​MemberDeclarationSyntaxExtensionsTests.cs Tests member reads, updates, and unsupported cases.
test/​StyleCop.Analyzers.Test/​Lightup/​LightupHelpersUnitTests.cs Tests custom fallback delegates.
test/​StyleCop.Analyzers.Test.CSharp9/​Lightup/​SyntaxWrapperCSharp9UnitTests.cs Tests function-pointer parameter wrapping.
test/​StyleCop.Analyzers.Test.CSharp7/​Lightup/​SyntaxWrapperCSharp7UnitTests.cs Tests pattern wrapping and conversions.
src/​StyleCop.Analyzers/​Lightup/​MemberDeclarationSyntaxExtensions.cs Adds derived-member fallback dispatch.
src/​StyleCop.Analyzers/​Lightup/​LightupHelpers.cs Supports fallback delegates and dual-hierarchy recognition.
src/​StyleCop.Analyzers/​Lightup/​BaseParameterSyntaxWrapper.cs Defines concrete parameter fallback support.
src/​StyleCop.Analyzers/​Lightup/​.generated/​StyleCop.Analyzers.CodeGeneration/​StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/​SyntaxWrapperHelper.g.cs Registers the generated parameter fallback.
src/​StyleCop.Analyzers/​Lightup/​.generated/​StyleCop.Analyzers.CodeGeneration/​StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator/​ExpressionOrPatternSyntaxWrapper.g.cs Uses fallback-aware instance checks.
CONTRIBUTING.md Documents syntax compatibility requirements.

Review effort: Balanced

Use UnitTests class names recognized by DerivedTestGenerator so member, parameter, and expression fallback regressions run on both legacy and modern Roslyn hosts.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings October 20, 2026 00:53

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No blocking defects were identified, and regression tests cover the changed compatibility paths; tests were not independently executed.

1 open issue
1 resolved since last review

Review effort: Balanced

@codecov

codecov Bot commented Oct 20, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.55157% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 97.63%. Comparing base (2b8bc7d) to head (9a2e968).
⚠️ Report is 4 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4357      +/-   ##
==========================================
+ Coverage   97.62%   97.63%   +0.01%     
==========================================
  Files        1336     1342       +6     
  Lines      149792   150378     +586     
  Branches     5098     5138      +40     
==========================================
+ Hits       146239   146829     +590     
+ Misses       2265     2247      -18     
- Partials     1288     1302      +14     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@AArnott
AArnott merged commit f5b5bb2 into master Oct 20, 2026
30 checks passed
@AArnott
AArnott deleted the aarnott-probable-invention branch October 20, 2026 01:14
This was referenced Nov 11, 2026
This was referenced Dec 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix lightup support for fallback base syntax types

2 participants