{"record":{"id":"1c38b96e88f96bf3","repo":"apple/pkl","slug":"expectedmoduleasreceiver","errorCode":"expectedModuleAsReceiver","errorMessage":"expectedModuleAsReceiver","messagePattern":"expectedModuleAsReceiver","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/stdlib/base/ModuleClassNodes.java","lineNumber":36,"sourceCode":"import com.oracle.truffle.api.CompilerDirectives;\nimport com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;\nimport com.oracle.truffle.api.dsl.Specialization;\nimport java.net.URI;\nimport org.pkl.core.runtime.*;\nimport org.pkl.core.stdlib.ExternalMethod1Node;\nimport org.pkl.core.stdlib.PklName;\n\n@PklName(\"Module\")\npublic final class ModuleClassNodes {\n  private ModuleClassNodes() {}\n\n  public abstract static class relativePathTo extends ExternalMethod1Node {\n    @Specialization\n    @TruffleBoundary\n    protected VmList eval(VmObjectLike self, VmObjectLike other) {\n      if (!self.isModuleObject()) {\n        CompilerDirectives.transferToInterpreter();\n        throw exceptionBuilder().evalError(\"expectedModuleAsReceiver\").build();\n      }\n      if (!other.isModuleObject()) {\n        CompilerDirectives.transferToInterpreter();\n        throw exceptionBuilder().evalError(\"expectedModuleAsArgument\").build();\n      }\n      var selfKey = VmUtils.getModuleInfo(self).getModuleKey();\n      var selfUri = selfKey.getUri();\n      var otherKey = VmUtils.getModuleInfo(other).getModuleKey();\n      var otherUri = otherKey.getUri();\n\n      var index = selfUri.toString().lastIndexOf('/');\n      if (index != -1) {\n        var baseUri = URI.create(selfUri.toString().substring(0, index + 1));\n        var relativizedUri = baseUri.relativize(otherUri);\n        if (!relativizedUri.isAbsolute()) {\n          var pathElements = relativizedUri.getPath().split(\"/\");\n          return VmList.create(pathElements, pathElements.length - 1);\n        }","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/stdlib/base/ModuleClassNodes.java#L18-L54","documentation":"Thrown by Module.relativePathTo when the receiver (the object the method is called on) is not a module object. Both endpoints must be modules because the method computes a URI-relative path between module keys; a non-module object has no module key/URI to relativize against.","triggerScenarios":"Calling relativePathTo on a plain object, Dynamic, List, or any non-module value: e.g. `someObject.relativePathTo(otherModule)` instead of `module.relativePathTo(otherModule)`.","commonSituations":"Calling the method inside a class or nested object where `this` is not the module, accidentally shadowing `module`, or importing the method conceptually as a free function and applying it to the wrong receiver.","solutions":["Call it on the module itself: `module.relativePathTo(other)` or the module's implicit receiver","Ensure the receiver is imported with `import \"...\"` so it is a module object","Use `(import(\"...\"))::relativePathTo(other)` style access if calling from another module","Verify you're not in a nested object scope where `this` refers to an inner object"],"exampleFix":"// before\nmyObject.relativePathTo(otherModule)\n// after\nmodule.relativePathTo(otherModule)","handlingStrategy":"validation","validationCode":"function isModuleReceiver(obj: Any): Boolean = obj is Module","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Call relativePathTo on the module binding, not nested objects","Avoid shadowing `module` inside class/object scopes","Ensure receivers come from import statements","Prefer `module.relativePathTo(...)` explicitly for clarity"],"tags":["pkl","module","receiver","stdlib"],"backgroundTag":"invalid-argument-value","analyzedSha":"f3efcbfc9b60d30053b0536d664948d7aa1b8673","analyzedAt":"2026-09-08T13:10:45.570Z","contentChangedAt":"2026-09-08T13:10:45.570Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}