Class CompileTimeConstraintEvaluator

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

public final class CompileTimeConstraintEvaluator extends Object
Evaluates a ConstraintExpr against a compile-time-constant subject value, returning a tri-state verdict. Used in phase 5 to turn a guaranteed runtime constraint Panic into a compile error when the constructor argument is a literal.

This is a tiny reflective interpreter over the real EK9 standard library. It constructs the subject and each constraint literal as actual org.ek9.lang.* objects via their _of(String) factory — the same factory the bytecode generator emits (see LiteralBytecodeGenerator) — then invokes the real EK9 operator (resolved through OperatorMap, e.g. >=_gteq). Because object construction and operator evaluation reuse the exact stdlib code the runtime uses, a compile-time verdict is byte-for-byte faithful to runtime behaviour for any constrainable base type (Integer, Float, Date, Time, DateTime, Duration, Money, Dimension, Colour, Character, String/RegEx, …) — there is no per-type special-casing.

AND/OR combine the leaf verdicts with three-valued (Kleene) logic; parentheses are transparent in the model. Only the leaf comparison is reflective; the boolean algebra stays in plain Java.

Deliberately CONSERVATIVE: it returns CompileTimeConstraintEvaluator.Verdict.FAIL only when it can prove the constraint is violated. Anything it cannot fully evaluate — a type that will not load, a literal that will not construct (or constructs to an unset value), an operator with no resolvable method, an operator result that is unset, or any reflective failure — yields CompileTimeConstraintEvaluator.Verdict.UNKNOWN, and the caller must NOT emit an error (the runtime check still applies). Crucially, because subject and literal are built with the same _of the runtime uses, the evaluator can never compute a verdict that diverges from runtime, so it can never raise a false-positive compile error on valid code.

  • Constructor Details

    • CompileTimeConstraintEvaluator

      public CompileTimeConstraintEvaluator()
  • Method Details

    • evaluate

      public CompileTimeConstraintEvaluator.Verdict evaluate(String subjectText, String subjectTypeFqn, ConstraintExpr constraint)
      Evaluate the constraint against a constant subject.
      Parameters:
      subjectText - the literal source text of the constructor argument (e.g. "15")
      subjectTypeFqn - the argument's fully qualified type (e.g. "org.ek9.lang::Integer")
      constraint - the constraint model (may be null)
      Returns:
      the verdict; only FAIL should trigger a compile error