Skip to content

CollisionResolvedTechPack silently misses TechPack protocol extensions #292

@bguidolim

Description

@bguidolim

Problem

CollisionResolvedTechPack (in DestinationCollisionResolver.swift) is a decorator that wraps any TechPack and overrides components while forwarding all other protocol members to inner.

If TechPack gains a new requirement without a default implementation, the compiler catches it — CollisionResolvedTechPack won't compile until it forwards the new member. This is safe.

However, if TechPack gains a new requirement with a default implementation (in a protocol extension), CollisionResolvedTechPack silently uses the default instead of forwarding to inner. If the wrapped pack overrides that default, the override is lost.

This is an inherent limitation of the decorator pattern in Swift — there is no auto-forwarding mechanism.

Mitigation Options

  1. Convention: Add a comment in TechPack.swift reminding contributors to update CollisionResolvedTechPack when adding new protocol members with defaults
  2. Test: Add a compile-time or runtime check that CollisionResolvedTechPack forwards all protocol members (e.g., a test that creates a mock with non-default values and verifies they survive wrapping)
  3. Alternative design: Replace the decorator with a mutable property on ComponentDefinition or a post-processing step that doesn't require wrapping

Current State

TechPack has 3 members with default implementations:

  • templateSectionIdentifiers — explicitly forwarded in wrapper ✓
  • templateValues(context:) — explicitly forwarded in wrapper ✓
  • declaredPrompts(context:) — explicitly forwarded in wrapper ✓

All defaults are currently forwarded, so there is no bug today. The risk is future additions.

References

  • Sources/mcs/Install/DestinationCollisionResolver.swift:131-177CollisionResolvedTechPack
  • Sources/mcs/TechPack/TechPack.swift:51-89TechPack protocol + extensions

Metadata

Metadata

Assignees

No one assigned

    Labels

    tech-debtTechnical debt and code quality improvements

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions