Fix unused warnings for methods implementing external interfaces#402
Draft
kjonescertinia wants to merge 5 commits intomainfrom
Draft
Fix unused warnings for methods implementing external interfaces#402kjonescertinia wants to merge 5 commits intomainfrom
kjonescertinia wants to merge 5 commits intomainfrom
Conversation
#397) Fixed regression where loop variables used only in for-loop conditions and increments were being incorrectly marked as unused. For example, `for (Integer i = 0; i < 2; i++)` would incorrectly flag `i` as unused. The issue was caused by `withUsageTracking(false)` preventing variable references in for control from being tracked. Removed this wrapper to allow proper usage tracking. Added comprehensive test coverage for: - Variables used only in condition - Variables used only in update/increment - Variables unused (should still be flagged) - Variables used in body (read or modified) - Multiple variable declarations in for loops All 697 tests pass with no regressions.
When initializing a List/Set with a ghosted element type (external namespace types without definitions), the variable usage tracking was being skipped. This caused variables used within the list initializer to be incorrectly flagged as unused. The fix ensures that parts.foreach(_.verify(input, context)) is called even when the element type lookup fails, maintaining proper variable usage tracking while skipping type compatibility checks for unavailable types.
…d-fixes-397-398 # Conflicts: # jvm/src/test/scala/com/nawforce/apexlink/plugin/UnusedTest.scala
…faces (fixes #401) Add hasAllInterfaces flag to track whether we have complete information about all implemented interfaces. When false, public/global methods are not flagged as unused since they may be implementing interfaces from external namespaces. - Add hasAllInterfaces lazy val to ApexClassDeclaration - Update UnusedPlugin to check hasAllInterfaces before flagging methods - Add 8 comprehensive tests covering various interface scenarios - Improve isComplete documentation in TypeDeclaration
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes issue #401 where public/global methods implementing interfaces from external namespaces were incorrectly flagged as unused.
Root cause: The UnusedPlugin didn't account for cases where interface information is incomplete due to external dependencies. Methods that appear unused locally may actually implement interface contracts from external packages.
Solution:
hasAllInterfacesflag toApexClassDeclarationto track interface completenessUnusedPlugin.couldBeUnused()to suppress warnings for public/global methods whenhasAllInterfacesis falseisCompleteflag inTypeDeclarationRelated fixes: This PR also includes fixes for issues #397 and #398:
Test plan
sbt scalafmtAllFixes #401