{"record":{"id":"72ed933ca87f9c30","repo":"apple/pkl","slug":"cannotinferparent-72ed93","errorCode":"cannotInferParent","errorMessage":"Cannot tell which parent to amend.","messagePattern":"Cannot tell which parent to amend\\.","errorType":"error_code","errorClass":"VmException","httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/ast/expression/member/InferParentWithinMethodArgumentNode.java","lineNumber":46,"sourceCode":"import org.pkl.core.runtime.VmLanguage;\nimport org.pkl.core.runtime.VmUtils;\n\npublic abstract class InferParentWithinMethodArgumentNode\n    extends AbstractInferParentFromMethodNode {\n  private final int argIndex;\n\n  public InferParentWithinMethodArgumentNode(\n      SourceSection sourceSection, VmLanguage language, int argIndex) {\n    super(sourceSection, language);\n    this.argIndex = argIndex;\n  }\n\n  @TruffleBoundary\n  private int getMethodSlot(FrameDescriptor frameDescriptor) {\n    var methodSlot = frameDescriptor.getAuxiliarySlots().get(VmUtils.METHOD_FRAME_SLOT_ID);\n    if (methodSlot == null) {\n      // used in intrinsic constructor e.g. pkl.base#List()\n      throw exceptionBuilder().evalError(\"cannotInferParent\").build();\n    }\n    return methodSlot;\n  }\n\n  @Override\n  protected Method getMethod(VirtualFrame frame) {\n    var method = (Method) frame.getAuxiliarySlot(getMethodSlot(frame.getFrameDescriptor()));\n    if (method == null) {\n      // used in FunctionN.apply()\n      CompilerDirectives.transferToInterpreter();\n      throw exceptionBuilder().evalError(\"cannotInferParent\").build();\n    }\n\n    return method;\n  }\n\n  @Override\n  protected @Nullable TypeNode getTypeNode(VirtualFrame frame, Method method) {","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/ast/expression/member/InferParentWithinMethodArgumentNode.java#L28-L64","documentation":"Pkl throws `cannotInferParent` when an amend-within-method-argument node looks up the enclosing method's frame auxiliary slot and it is absent. InferParentWithinMethodArgumentNode.getMethodSlot notes this happens in intrinsic constructors such as `pkl.base#List()`, where no method frame slot exists to identify the parent.","triggerScenarios":"Using implicit-parent amendment syntax (`...` / inferred receiver) as an argument to an intrinsic constructor like `List(...)`, `Set(...)`, or `Map(...)` where no enclosing Pkl method frame exists.","commonSituations":"Writing `List(...)` with amendment shorthand at module top level or inside non-method scopes; calling intrinsic collection constructors from contexts Pkl cannot attribute to a method.","solutions":["Make the target explicit instead of relying on inference (e.g. pass the object directly: `List(obj.elements)`).","Move the expression into a proper method context where a method frame exists.","Replace the intrinsic constructor call with an object literal form (`new Listing { ... }`)."],"exampleFix":"// before\nList(...) // cannot infer parent\n// after\nList(someListing.elements)","handlingStrategy":"validation","validationCode":"// Pkl: pass explicit values to intrinsic constructors\nList(someListing.elements) // no inferred parent needed","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Avoid amendment shorthand as arguments to intrinsic constructors (List/Set/Map).","Use explicit object literals or pass values directly.","Ensure the expression evaluates within a real Pkl method scope."],"tags":["pkl","amendment","intrinsic","scope"],"backgroundTag":"unsupported-operation","analyzedSha":"f3efcbfc9b60d30053b0536d664948d7aa1b8673","analyzedAt":"2026-09-08T13:10:45.570Z","contentChangedAt":"2026-09-08T13:10:45.570Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}