Skip to content

fix: Track variable usage in ghosted type list initializers (fixes #398)#400

Merged
kjonescertinia merged 3 commits intomainfrom
fix/issue-398-ghosted-type-list-unused
Nov 25, 2025
Merged

fix: Track variable usage in ghosted type list initializers (fixes #398)#400
kjonescertinia merged 3 commits intomainfrom
fix/issue-398-ghosted-type-list-unused

Conversation

@kjonescertinia
Copy link
Contributor

Summary

  • Fixed false positive unused variable warnings when variables are used within List/Set initializers with ghosted element types
  • Ghosted types are external namespace types without available definitions (e.g., ext__Type__c)
  • Root cause: SetOrListCreatorRest.verify() was returning early without tracking variable usage when the element type lookup failed

Changes

  • Creator.scala: Added parts.foreach(_.verify(input, context)) call before early return when element type is ghosted, ensuring variable usage is tracked even when type compatibility checks are skipped
  • UnusedTest.scala: Added 3 comprehensive test cases covering:
    • Single variable used in ghosted type list initializer
    • Multiple variables used in ghosted type list elements
    • Unused variable correctly flagged even with ghosted type lists

Test plan

  • All existing tests pass (697 total)
  • New unit tests verify the fix
  • Tested against minimal reproduction case with external namespace types
  • Code formatted with sbt scalafmtAll

Fixes #398

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.
…-type-list-unused

# Conflicts:
#	jvm/src/test/scala/com/nawforce/apexlink/plugin/UnusedTest.scala
@kjonescertinia kjonescertinia merged commit d80f95d into main Nov 25, 2025
1 check passed
@kjonescertinia kjonescertinia deleted the fix/issue-398-ghosted-type-list-unused branch November 25, 2025 10:03
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.

False Positive: Unused Variable Warnings for String Variables with Multi-line Assignments

2 participants