Class Redeclaration

java.lang.Object
org.ek9lang.compiler.repair.Redeclaration

public final class Redeclaration extends Object
THE E50050 repair - a name declared a second time with <- - where the second <- has ONE reading, for every editing tool. Use this; do not re-derive it. Where two readings compile, the MCP RedeclarationHint names both instead.

<- declares a NEW variable, so a second one for a name already in scope never compiles (E50050). Two cases leave a single reading, and each becomes an assignment within its own line:

  • The member's return, declared again in its body - rtn <- String() under <- rtn as String?. The signature cannot be removed, so the body can only be assigning it: rtn: String(). 154 of the 223 E50050 refusals in the harness record.
  • A local used between its two declarations - full <- ..., a println(full), then full <- ... again. Replacing the earlier line instead would use full before it is declared (E08010, measured 2026-09-29), so the second can only be full := ....

With nothing between them both readings compile and differ - reassigning runs the first value too - so that case is skipped and the hint stands. The caller re-verifies whatever this proposes.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final record 
    A second declaration as the E50050 message names it - THE reading of that message for this repair and for the MCP RedeclarationHint: the name, the line declaring it again, the line that declared it first.
    static final record 
    The rewritten text and one note per rewrite; notes empty means nothing moved.
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    True when text declares a name twice with <-, or declares with <- a name it also returns - the cheap gate before a probe compile.
    repair(String text, List<Map<String,Object>> diagnostics)
    Make each second declaration an assignment where it has one reading.
    (package private) static boolean
    usedBetween(List<String> lines, int earlierLine, int line, String name)
    Is name read on a line strictly between the two declarations - outside double-quoted Strings and comments (a backtick String's ${name} is a read)?

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • mayApply

      public static boolean mayApply(String text)
      True when text declares a name twice with <-, or declares with <- a name it also returns - the cheap gate before a probe compile.
    • repair

      public static Redeclaration.Result repair(String text, List<Map<String,Object>> diagnostics)
      Make each second declaration an assignment where it has one reading. Driven by the diagnostics: the code must be E50050 and its message must name both lines. Rewrites within one line.
    • usedBetween

      static boolean usedBetween(List<String> lines, int earlierLine, int line, String name)
      Is name read on a line strictly between the two declarations - outside double-quoted Strings and comments (a backtick String's ${name} is a read)?