Skip to content

fix: filter non-importable targets from conflict resolution#160

Open
tylerprete wants to merge 1 commit into
stackb:masterfrom
tylerprete:tylerp/fix-binary-conflict-resolution
Open

fix: filter non-importable targets from conflict resolution#160
tylerprete wants to merge 1 commit into
stackb:masterfrom
tylerprete:tylerp/fix-binary-conflict-resolution

Conversation

@tylerprete

Copy link
Copy Markdown

Summary

Fixes #159.

When both a scala_binary and scala_library exist in the same package with overlapping source globs, the binary could incorrectly win dependency resolution. While isImportable() correctly prevents binary targets from registering exports, the resolve phase's conflict resolution had no filtering for non-importable targets — it selected arbitrarily without checking target type.

This PR adds filterNonImportableConflicts() in ResolveImports() which removes binary/test symbols from consideration during conflict resolution. The key behaviors:

  • Library always wins over binary/test: When a scala_library and scala_binary both provide the same symbol, the library is chosen.
  • Binary-only packages still work: If no importable (library) alternative exists, the original symbol is returned unchanged.
  • Multiple library conflicts preserved: If multiple libraries conflict (after filtering out binaries), the remaining conflicts are passed through to the existing conflict resolver chain.
  • No shared state mutation: New Symbol structs are allocated to avoid mutating the shared trie state.

Test plan

  • Added unit tests for filterNonImportableConflicts() covering all cases:
    • Library primary with binary conflict (binary filtered out)
    • Binary primary with library conflict (library wins)
    • Test primary with library conflict (library wins)
    • Binary primary with binary conflict (no importable alternative, returns original)
    • Two libraries + binary conflict (binary filtered, library conflict preserved)
    • Binary primary with two library conflicts (first library wins, conflict preserved)
  • Full //language/scala:scala_test suite passes
  • //pkg/resolver:resolver_test suite passes

🤖 Generated with Claude Code

…tion

When both a scala_binary and scala_library exist in the same package with
overlapping source globs, the binary could incorrectly win dependency
resolution. While isImportable() correctly prevents binary targets from
registering exports, the resolve phase's conflict resolution had no
filtering for non-importable targets.

Add filterNonImportableConflicts() which removes binary/test symbols from
consideration during conflict resolution. Library targets always win over
binary/test targets for the same symbol.

Fixes stackb#159

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

scala_binary targets win ambiguous resolve when sharing srcs with scala_library

1 participant