Class TraitMethodConflictDetector

java.lang.Object
org.ek9lang.compiler.phase5.TraitMethodConflictDetector

final class TraitMethodConflictDetector extends Object
Detects when multiple traits implemented by an aggregate have methods with the same signature. When this occurs, the developer MUST manually override the method to resolve the conflict. This is NOT an anti-pattern - it's a required language feature.

This detector is used to EXCLUDE conflicting methods from E11023 (Missing 'by' delegation) detection. If a method must be manually implemented due to trait conflicts, it should not be flagged as "missing by delegation".

Example of trait conflict:

trait Logger
  log() abstract -> message as String

trait Auditor
  log() abstract -> message as String  // Same signature!

class MyClass with trait of Logger, Auditor
  // MUST manually override log() - cannot use 'by' for both
  override log() -> message as String
    // Custom implementation combining both
  • Constructor Details

    • TraitMethodConflictDetector

      TraitMethodConflictDetector()
  • Method Details

    • findConflictingMethodSignatures

      Set<String> findConflictingMethodSignatures(IAggregateSymbol aggregate)
      Find method signatures that appear in multiple traits implemented by this aggregate.
      Parameters:
      aggregate - The aggregate implementing traits
      Returns:
      Set of method signatures (name + parameter types) that conflict across traits
    • hasConflict

      boolean hasConflict(IAggregateSymbol aggregate, MethodSymbol method)
      Check if a specific method has a conflict across traits. Conflicts are keyed by SIGNATURE (name and parameter types), so a conflict on one overload does not excuse a sibling overload of the same name.
      Parameters:
      aggregate - The aggregate implementing traits
      method - The method to check
      Returns:
      true if this method's signature conflicts across multiple traits
    • hasConflictForTrait

      boolean hasConflictForTrait(Set<String> conflictingSignatures, IAggregateSymbol trait)
      Check if any of the conflicting signatures is one of the given trait's own methods. A conflict between OTHER traits compels nothing of this one.
      Parameters:
      conflictingSignatures - as found by findConflictingMethodSignatures(IAggregateSymbol)
      trait - The trait to check
      Returns:
      true if the trait declares a method whose signature is in the conflicting set