Class SameRuntimeOperator

java.lang.Object
org.ek9lang.compiler.support.SameRuntimeOperator

public final class SameRuntimeOperator extends Object
THE test that two DIFFERENTLY SPELT operators are one runtime operator - use this, do not re-derive it.

Some operators have more than one spelling: unary - and ~ are both negation, _negate (OperatorMap.getPrefixForward(String); word not is a third spelling, but cannot be declared). Two such declarations with the same parameter types are the same method once lowered, so they are judged by the runtime name OperatorMap.resolvedMethodName(MethodSymbol) gives them - derived from the map, never a hand list of aliases.

D59 (2026-10-21): a class declaring both unary - and ~ compiled and failed at class load with ClassFormatError: Duplicate method name "_negate", because the duplicate check matched EK9 names. Phase 2's NoDuplicateOperationsOrError reports the second in one type, and phase 3's override check reports a sub-type spelling an inherited operator differently (super ~, sub-type -), which compiled and ran different code for -x and ~x. Both are E02030.

  • Method Details

    • differentSpellingsOfOne

      public static boolean differentSpellingsOfOne(MethodSymbol first, MethodSymbol second)
      Are these two operators, spelt differently, one runtime operator with the same parameter types?
      Parameters:
      first - an operator
      second - another operator
      Returns:
      true when both lower to the same runtime method and only the spelling differs
    • runtimeName

      public static String runtimeName(MethodSymbol operator)
      The runtime name of an operator, as OperatorMap.resolvedMethodName(MethodSymbol) gives it (arity-aware).
      Parameters:
      operator - an operator
      Returns:
      its runtime method name
    • otherSpellingIn

      public static Optional<MethodSymbol> otherSpellingIn(MethodSymbol operator, Iterable<MethodSymbol> candidates)
      The first of candidates that is a different spelling of the same runtime operator as operator.
      Parameters:
      operator - the operator asked about
      candidates - the operators to look through
      Returns:
      the other spelling, if any