apple/pkl · error · VmException

methodNotDefined3

methodNotDefined3

Error message

methodNotDefined3

What it means

ExternalMethod3Node implements three-argument stdlib methods. The @Fallback fires when the dynamic types of receiver + three arguments match no defined specialization, producing the "methodNotDefined3" eval error with the member name and each argument's class. It is Pkl's way of saying 'no overload for these types'.

Source

Thrown at pkl-core/src/main/java/org/pkl/core/stdlib/ExternalMethod3Node.java:38

import com.oracle.truffle.api.dsl.NodeChild;
import org.pkl.core.ast.ExpressionNode;
import org.pkl.core.runtime.VmUtils;

@NodeChild(value = "arg1Node", type = ExpressionNode.class)
@NodeChild(value = "arg2Node", type = ExpressionNode.class)
@NodeChild(value = "arg3Node", type = ExpressionNode.class)
public abstract class ExternalMethod3Node extends ExternalMethodNode {
  protected abstract ExpressionNode getArg1Node();

  protected abstract ExpressionNode getArg2Node();

  protected abstract ExpressionNode getArg3Node();

  @Fallback
  @TruffleBoundary
  protected Object fallback(
      @SuppressWarnings("unused") Object receiver, Object arg1, Object arg2, Object arg3) {
    throw exceptionBuilder()
        .evalError(
            "methodNotDefined3",
            getQualifiedMemberName(),
            VmUtils.getClass(arg1),
            VmUtils.getClass(arg2),
            VmUtils.getClass(arg3))
        .withProgramValue("Argument 1", arg1)
        .withProgramValue("Argument 2", arg2)
        .withProgramValue("Argument 3", arg3)
        .build();
  }

  public interface Factory {
    ExternalMethod3Node create(
        ExpressionNode receiverNode,
        ExpressionNode arg1Node,
        ExpressionNode arg2Node,
        ExpressionNode arg3Node);

View on GitHub (pinned to f3efcbfc9b)

Solutions

  1. Match each reported argument class to the documented parameter types.
  2. Wrap or convert arguments (lambdas vs values, Int vs String) explicitly.
  3. Print/debug the argument values with `trace()` to find which one diverges from expectation.
  4. Consult the stdlib docs for the exact three-argument overload in your Pkl version.

Example fix

// before
list.fold(list, init, acc) // wrong: fold(init, (acc, elem) -> ...) two-arg form
// after
list.fold(init) { acc, elem -> acc + elem }
Defensive patterns

Strategy: type-guard

Validate before calling

// Pkl
assert(isFunction(f) || isClass(f), "3rd argument must be a function or class")

Type guard

function isFunction(x) = x is Function

Prevention

When it happens

Trigger: Calling a three-argument stdlib method (e.g. List.sort with comparator args, String.take/drop variants) where one or more of the three arguments has an unexpected type (null, List where Function expected, etc.).

Common situations: Passing a lambda where a List or Int is expected (or vice versa); a null slipping through from an amending default; copy-paste between similar methods with different signatures.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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