apple/pkl · error

operatorNotDefined2

operatorNotDefined2

Error message

operatorNotDefined ${leftClass} (via operatorNotDefined helper)

What it means

`&&` short-circuit specialization requires both sides to be Boolean; if the right operand evaluates to a non-Boolean (signalled via UnexpectedResultException), Pkl throws operatorNotDefined via the helper, reported as operatorNotDefined2 for `&&`. It indicates the right-hand side of a logical-and is not a Boolean.

Source

Thrown at pkl-core/src/main/java/org/pkl/core/ast/expression/binary/LogicalAndNode.java:36

import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.NodeInfo;
import com.oracle.truffle.api.nodes.UnexpectedResultException;
import com.oracle.truffle.api.source.SourceSection;
import org.pkl.core.ast.ExpressionNode;

@NodeInfo(shortName = "&&")
public abstract class LogicalAndNode extends ShortCircuitingExpressionNode {
  protected LogicalAndNode(SourceSection sourceSection, ExpressionNode rightNode) {
    super(sourceSection, rightNode);
  }

  @Specialization
  protected boolean eval(VirtualFrame frame, boolean left) {
    try {
      return left && rightNode.executeBoolean(frame);
    } catch (UnexpectedResultException e) {
      throw operatorNotDefined(true, e.getResult());
    }
  }
}

View on GitHub (pinned to f3efcbfc9b)

Solutions

  1. Make the right operand a real Boolean expression (comparison, `.isEmpty`, etc.)
  2. Fix the type of the referenced property on the right side
  3. Add an explicit type annotation (`Boolean`) so it fails at type-check time

Example fix

// before (Pkl)
val enabled = true && 1
// after
val enabled = true && (count > 0)
Defensive patterns

Strategy: type-guard

Validate before calling

function isValidAndOperand(right) { return typeof right === 'boolean'; }

Type guard

const isBool = (v) => typeof v === 'boolean';

Prevention

When it happens

Trigger: `true && <nonBoolean>` e.g. `true && 1` or `flag && someString` where the right side is a mistyped property or a lazy expression producing a non-Boolean.

Common situations: Config authors treating truthy integers/strings as conditions (habit from other languages) or a property referenced on the right side having an unintended type.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


AI-assisted analysis of apple/pkl@f3efcbfc9b (2026-09-08). Data as JSON: /api/errors/827a5a0fabd31ba5. Report an issue: GitHub.