Skip to content

Analyzer#5

Open
halotukozak wants to merge 39 commits intomasterfrom
analyzer
Open

Analyzer#5
halotukozak wants to merge 39 commits intomasterfrom
analyzer

Conversation

@halotukozak
Copy link
Copy Markdown
Owner

No description provided.

halotukozak and others added 28 commits February 18, 2026 19:29
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add scalatest 3.2.19 as Test dependency using scalatestVersion
- Enable Test / fork := true for proper classpath handling
- Change += to ++= with Seq for multiple dependencies
- Replace Scala 2 Global-based AnalyzerTest with Scala 3 ContextBase + Compiler pattern
- Implement compile() with fresh ContextBase per invocation to avoid stale state
- Inject AnalyzerPlugin via loadRoughPluginsList override
- Add CompilationResult capturing errorCount, warningCount, errors, warnings
- Implement compileWithoutPlugin() for canary tests
- Add assertErrors(), assertNoErrors(), assertWarnings() helpers
- Preserve ScalaInterpolator from Scala 2
- Fix: Use Yusejavacp instead of usejavacp (Scala 3 API)
- Remove all old Scala 2 test files that cannot compile on Scala 3
- 6 tests proving plugin loads, Reporter captures diagnostics, tests not vacuously green
- Tests: valid code compiles, error/warning capture, fresh context per compilation
- Auto-fixed: non-exhaustive match produces reliable warnings in Scala 3
- Add Scala 3 transformTypeDef implementation with flag checks
- Check for Case, Final, and Sealed flags using Flags API
- Only report error for static (non-inner) case classes (SI-4440)
- Add comprehensive tests covering final, non-final, sealed, inner cases
- All 8 tests pass
…tests

- Migrate ImplicitParamDefaults from Scala 2 to Scala 3 using DefDef.termParamss
- Detect implicit/given parameters with default values via Flags.HasDefault
- Add 12 tests covering implicit params, given params, class constructors, multi-param lists

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…nce checks

- Migrate CatchThrowable from Scala 2 to Scala 3 using transformTry and tpd API
- Use ctx.definitions.ThrowableClass.typeRef with =:= for exact type match
- Handle Bind, Typed, Alternative patterns recursively via checkPattern helper
- Skip synthetic CaseDef spans from custom handlers (isSourceDerived check)
- Detect custom extractors via UnApply pattern exclusion
- Add 8 comprehensive tests covering direct catch, specific exceptions,
  nested try, custom extractors, alternative patterns, and custom handlers

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…rect detection

- Fix bug: sel.rename.isEmpty (TermName) never true for non-renamed imports;
  use sel.renamed.isEmpty (Tree) which correctly checks for EmptyTree
- Add trailing comma per scalafmt rules
- ImportJavaUtilTest passes: detects `import java.util`, ignores other imports

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…classes

- Fix isDefinitionSite to handle module class/companion module span checking
- Object definitions with @bincompat no longer false-positive as usage sites
- Tests verify both definition-site allowance and usage-site rejection
… member lookup

- Migrate ThrowableObjects from Scala 2 to Scala 3 using transformTypeDef and tpd API
- Use ctx.definitions.ThrowableClass.typeRef with <:< for subtype check
- Check Module flag and isClass to identify object definitions
- Use symbol.info.member(termName("fillInStackTrace")) for member lookup
- Detect unoverridden fillInStackTrace via alternatives.forall(_.symbol.owner == throwableSym)
- Add 5 tests: no-override rejected, NoStackTrace allowed, mixed, regular object, class not flagged

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…rarg detection

- Rewrite from Scala 2 to Scala 3 API using transformApply and paramInfoss
- Detect varargs via isRepeatedParam on parameter type info
- Distinguish compiler-generated SeqLiteral from explicit splice (seq*)
- Count SeqLiteral elements to validate @atleast annotation
- Extract annotation class via Symbols.getClassIfDefined
- Add tests for too-few args, sufficient args, and collection splice
…ng passed as function

- Rewrite from Scala 2 to Scala 3 API using transformApply
- Check if parameter type is function via ctx.definitions.isFunctionType
- Check if argument type is Nothing via subtype check against NothingType
- Include helpful message with paramTpe.show for type display
- Add tests: throw as function arg, proper function, lambda wrap, non-function Nothing, multi-param, Function0
…idation

- Override transformUnit to validate required base package from per-rule argument
- Recursive @tailrec validation through nested PackageDef nodes
- Skip imports, recurse into single non-import stat
- Report error when required base package not found in package hierarchy
- Tests validate: correct package (pass), wrong package (error), nested package (pass)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…tests

- Parse semicolon-separated argument into rejected symbol names set
- Override transformIdent, transformSelect, transformApply, transformNew, transformOther
- Check symbol.fullName against rejectedSymbols set for each tree node
- Tests verify single usage, multiple usages, and no-match scenarios
…ection

- Rewrite from Scala 2 to Scala 3 using transformTypeDef with derivesFrom check
- Document that Scala 3 auto-finalizes value classes (rule is no-op)
- Add comprehensive tests covering final, non-final, generic value classes
- All 5 tests pass; full analyzer suite (63 tests) passes

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…t checks

- Level.Off default (opt-in rule), transformValDef with ConstantType detection
- Three diagnostic cases: lowercase/non-final literal constants, non-final UpperCamelCase vals, explicit type on final literal constants
- Skip private, module, param, synthetic, mutable vals
- 8 tests covering all cases: correct finals, lowercase/non-final warnings, explicit type, non-constant vals, private vals

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ction

- Walk owner chain via ownersIterator to detect inline method context
- Filter definition sites to avoid false positives on @macroPrivate declarations
- Graceful no-op when @macroPrivate annotation not on classpath
- Override transformIdent and transformSelect for all reference tree types

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ection

- ShowAst emits AST representation at Error level for @showAst-annotated definitions
- Uses Symbols.getClassIfDefined for annotation lookup with graceful no-op
- Overrides transformValDef, transformDefDef, transformTypeDef for member definitions
- Test suite validates annotation on val/def/class, no false positives, classpath safety

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
… type detection

- ExplicitGenerics warns when @explicitGenerics methods called with inferred type args
- Span heuristic: inferred TypeTree args share fun span, explicit args have distinct spans
- Uses Symbols.getClassIfDefined for annotation lookup with graceful no-op
- Checks allOverriddenSymbols for annotation inheritance
- Test suite validates inferred vs explicit, multi-param, non-annotated, classpath safety
- Override pluginOptions in test to isolate rule from other rule interference

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…aversal

- Use transformUnit with manual recursive traversal tracking discarded position
- Handle Block, Template, If, WhileDo, Try, CaseDef, Match, DefDef, ValDef, TypeDef, PackageDef
- Use classSymbol.derivesFrom for Task type detection (not raw typeRef subtype check)
- Graceful no-op when monix.eval.Task not on classpath

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
… detection

- transformDefDef with Flags.Implicit/Given check on parameters
- isFunctionLikeType helper: isFunctionType, isContextFunctionType, PartialFunctionClass
- 7 tests: implicit/using with Function/ContextFunction/PartialFunction types
- Fix ConstantDeclarations regressions in CanaryTest, FindUsagesTest, ThrowableObjectsTest, BasePackageTest (val -> def for non-constant test values)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…pe detection

Checks implicit val/def and named given definitions for explicit type annotations.
Uses !tpt.span.isSourceDerived heuristic to detect inferred types. Skips anonymous
givens (Synthetic flag) and non-implicit definitions. Registered in AnalyzerPlugin
(was never registered in Scala 2).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…asses extend AnyVal

Warns on implicit classes that do not extend AnyVal to avoid runtime overhead.
Uses sym.derivesFrom(AnyValClass) pattern. Simplified approach: always checks all
implicit classes (dropped the all/top-level-only argument from Scala 2).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Delete Any2StringAdd.scala (rule obsolete in Scala 3)
- Remove Any2StringAdd from AnalyzerPlugin rules list
- Change unknown rule name handling from warning to silent ignore for backward compatibility
- Port Scala 2 ValueEnumExhaustiveMatch to Scala 3 dotc API
- Use Symbols.getClassIfDefined for runtime ValueEnum class resolution
- Detect non-exhaustive matches on ValueEnum-typed selectors via transformMatch
- Handle wildcard, guard, alternative, bind, literal, and select patterns
- Add 7 test cases with self-contained ValueEnum stubs (3 error, 4 no-error)
- All 120 analyzer tests pass
- Replace implicit def stringContextToScalaInterpolator with extension method on StringContext
- Remove AnalyzerTest companion object (ScalaInterpolator class no longer needed)
- Apply scalafmt to all analyzer main and test sources (7 main + 17 test files reformatted)
- All 120 tests pass with zero implicit keywords in analyzer's own source code

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Delete `FinalValueClasses.scala` and its test suite (`FinalValueClassesTest.scala`) as it is a no-op in Scala 3 due to compiler's automatic finalization of value classes.
- Remove `FinalValueClasses` from `AnalyzerPlugin` rules list.
- Simplify test scaffolding by eliminating redundant local annotation definitions and stubs.
- Improve error reporting for unrecognized analyzer rules in `AnalyzerPlugin`.
- Replace explicit Context passing in rules with `using Context` for conciseness.
- Convert methods returning constant values into private `val` definitions.
- Simplify error-checking logic by removing redundant parentheses and conditions.
- Standardize test sources by removing local annotation definitions.
- Adjust indentation and spacing inconsistencies across test cases.
@halotukozak halotukozak self-assigned this Feb 21, 2026
Copilot AI review requested due to automatic review settings February 21, 2026 12:22
… planning

- Delete `.planning/phases/02-test-infrastructure/02-RESEARCH.md` as it is no longer relevant.
- Phase-related architecture, patterns, and requirements have been implemented or archived.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR re-enables the analyzer subproject and migrates the AVSystem static analyzer compiler plugin + its test harness to Scala 3 / Dotty APIs, with updated rule implementations and refreshed rule-focused tests.

Changes:

  • Enable/aggregate the analyzer project in build.sbt and add Scala 3 compiler + ScalaTest dependencies for analyzer tests.
  • Rewrite the analyzer plugin infrastructure from Scala 2 Global-based compiler plugins to Scala 3 StandardPlugin + PluginPhase rules.
  • Replace/trim and modernize analyzer rule tests to run via an in-process Scala 3 compiler harness (AnalyzerTest), adding canary coverage.

Reviewed changes

Copilot reviewed 47 out of 49 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
build.sbt Re-enables analyzer project, aggregates it, and defines its dependencies/settings.
analyzer/src/test/scala/com/avsystem/commons/analyzer/AnalyzerTest.scala New Scala 3 compilation harness (compile helpers + result capture).
analyzer/src/test/scala/com/avsystem/commons/analyzer/CanaryTest.scala Adds canary tests validating harness and diagnostic capture paths.
analyzer/src/test/scala/com/avsystem/commons/analyzer/TestUtils.scala Simplifies test utilities for Scala 3 (keeps @atLeast varargs helper).
analyzer/src/test/scala/com/avsystem/commons/analyzer/VarargsAtLeastTest.scala Updates varargs tests for Scala 3 syntax/harness.
analyzer/src/test/scala/com/avsystem/commons/analyzer/ValueEnumExhaustiveMatchTest.scala Isolates rule via plugin options + adjusts test source.
analyzer/src/test/scala/com/avsystem/commons/analyzer/ThrowableObjectsTest.scala Expands and clarifies rule scenarios for Scala 3 harness.
analyzer/src/test/scala/com/avsystem/commons/analyzer/ShowAstTest.scala Adds new tests for @showAst behavior.
analyzer/src/test/scala/com/avsystem/commons/analyzer/NothingAsFunctionArgumentTest.scala Replaces large Scala 2 suite with focused Scala 3 cases.
analyzer/src/test/scala/com/avsystem/commons/analyzer/ImportJavaUtilTest.scala Adds a non-triggering import test and formatting updates.
analyzer/src/test/scala/com/avsystem/commons/analyzer/ImplicitValueClassesTest.scala Reworks coverage and isolates rule via plugin options.
analyzer/src/test/scala/com/avsystem/commons/analyzer/ImplicitTypesTest.scala Adds Scala 3 given/implicit coverage and isolates rule.
analyzer/src/test/scala/com/avsystem/commons/analyzer/ImplicitParamDefaultsTest.scala Adds Scala 3 using-default coverage + formatting tweaks.
analyzer/src/test/scala/com/avsystem/commons/analyzer/ImplicitFunctionParamsTest.scala Replaces broad Scala 2 suite with Scala 3 focused cases.
analyzer/src/test/scala/com/avsystem/commons/analyzer/FindUsagesTest.scala Updates to new pluginOptions override and expands cases.
analyzer/src/test/scala/com/avsystem/commons/analyzer/FinalValueClassesTest.scala Removes obsolete Scala 2-era test file.
analyzer/src/test/scala/com/avsystem/commons/analyzer/FinalCaseClassesTest.scala Updates expectations for inner case classes + formatting.
analyzer/src/test/scala/com/avsystem/commons/analyzer/ExplicitGenericsTest.scala Switches rule to warning-level assertions + new Scala 3-friendly cases.
analyzer/src/test/scala/com/avsystem/commons/analyzer/DiscardedMonixTaskTest.scala Replaces broad suite with targeted Scala 3 block/loop cases.
analyzer/src/test/scala/com/avsystem/commons/analyzer/ConstantDeclarationsTest.scala Refactors tests into smaller focused cases; isolates rule.
analyzer/src/test/scala/com/avsystem/commons/analyzer/CheckMacroPrivateTest.scala Reworks tests around Scala 3 inline semantics and rule isolation.
analyzer/src/test/scala/com/avsystem/commons/analyzer/CheckBincompatTest.scala Minor formatting update for Scala 3 harness.
analyzer/src/test/scala/com/avsystem/commons/analyzer/CatchThrowableTest.scala Formatting + Scala 3 import adjustments.
analyzer/src/test/scala/com/avsystem/commons/analyzer/BasePackageTest.scala Simplifies cases + changes base package argument and expectations.
analyzer/src/test/scala/com/avsystem/commons/analyzer/Any2StringAddTest.scala Removes obsolete/unwanted test file.
analyzer/src/main/scala/com/avsystem/commons/analyzer/AnalyzerRule.scala New Scala 3 PluginPhase base rule abstraction + reporting helper and Level enum.
analyzer/src/main/scala/com/avsystem/commons/analyzer/AnalyzerPlugin.scala New Scala 3 StandardPlugin implementation and options parsing.
analyzer/src/main/scala/com/avsystem/commons/analyzer/VarargsAtLeast.scala Port of rule to Scala 3 typed trees and annotations inspection.
analyzer/src/main/scala/com/avsystem/commons/analyzer/ValueEnumExhaustiveMatch.scala Port of match exhaustiveness rule to Scala 3 AST/symbol APIs.
analyzer/src/main/scala/com/avsystem/commons/analyzer/ThrowableObjects.scala Port of Throwable-object detection to Scala 3 symbol/member APIs.
analyzer/src/main/scala/com/avsystem/commons/analyzer/ShowAst.scala Port to Scala 3 + reports tree.show on annotated defs.
analyzer/src/main/scala/com/avsystem/commons/analyzer/NothingAsFunctionArgument.scala Port rule to Scala 3 apply/param type inspection.
analyzer/src/main/scala/com/avsystem/commons/analyzer/ImportJavaUtil.scala Port import check to Scala 3 import tree representation.
analyzer/src/main/scala/com/avsystem/commons/analyzer/ImplicitValueClasses.scala Simplified Scala 3 implementation using flags/type inheritance.
analyzer/src/main/scala/com/avsystem/commons/analyzer/ImplicitTypes.scala New Scala 3 implementation using spans to detect inferred types.
analyzer/src/main/scala/com/avsystem/commons/analyzer/ImplicitParamDefaults.scala Port rule to Scala 3 param flags (HasDefault + given/implicit).
analyzer/src/main/scala/com/avsystem/commons/analyzer/ImplicitFunctionParams.scala Port rule to Scala 3 function/context-function/PartialFunction checks.
analyzer/src/main/scala/com/avsystem/commons/analyzer/FindUsages.scala Port to Scala 3 transform hooks and symbol fullName matching.
analyzer/src/main/scala/com/avsystem/commons/analyzer/DiscardedMonixTask.scala Port/simplification to Scala 3 tree hooks for discarded Task detection.
analyzer/src/main/scala/com/avsystem/commons/analyzer/ConstantDeclarations.scala Port rule to Scala 3 flags/types/spans; keeps default Level.Off.
analyzer/src/main/scala/com/avsystem/commons/analyzer/CheckMacroPrivate.scala Port macroPrivate usage check to Scala 3 inline-owner semantics + span heuristics.
analyzer/src/main/scala/com/avsystem/commons/analyzer/CheckBincompat.scala Port bincompat usage check to Scala 3 and improves definition-site detection.
analyzer/src/main/scala/com/avsystem/commons/analyzer/CatchThrowable.scala Port catch-pattern inspection to Scala 3 pattern trees.
analyzer/src/main/scala/com/avsystem/commons/analyzer/BasePackage.scala Port base-package enforcement to Scala 3 PackageDef traversal.
analyzer/src/main/scala/com/avsystem/commons/analyzer/FinalCaseClasses.scala Port rule to Scala 3 TypeDef/Flags checks.
analyzer/src/main/scala/com/avsystem/commons/analyzer/Any2StringAdd.scala Removes obsolete Scala 2 implementation.
analyzer/src/main/scala/com/avsystem/commons/analyzer/FinalValueClasses.scala Removes obsolete Scala 2 implementation.
analyzer/src/main/resources/... (No changes shown in diff.)
.planning/phases/02-test-infrastructure/02-RESEARCH.md Adds research notes documenting Scala 3 plugin test harness approach.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Feb 21, 2026

📊 Test Compilation Benchmark

Scala Version Average Time
Scala 2.13 17.163s
Scala 3 27.119s

Result: Scala 3 is 9.956s slower (58.01%) ⚠️

…y passing rule names to the base constructor, convert some `val` fields to `lazy val`, and apply minor formatting improvements.
… streamline validation logic, add or update `requiredSymbols`, and improve formatting consistency.
…s` for consistency across implementations.
…rter`, remove `CompilationResult`, and streamline error and warning assertions.
…lidation logic, ensure consistency in imports, and enhance code clarity.
…on logic, and eliminate unused `dumpTree` and `pidHasDirectQualifier` methods.
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.

2 participants