{"record":{"id":"26e1f98a0b2c8894","repo":"apple/pkl","slug":"externalclass","errorCode":null,"errorMessage":"externalClass","messagePattern":"externalClass","errorType":"error_code","errorClass":"VmReferenceAccessError","httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/runtime/VmReference.java","lineNumber":243,"sourceCode":"    }\n    // restriction: cannot reference Listing/Mapping.default\n    if (clazz.getPClass().getInfo() == PClassInfo.Listing\n        || clazz.getPClass().getInfo() == PClassInfo.Mapping) {\n      var errorType =\n          property.equals(\"default\")\n              ? VmReferenceAccessErrorType.DEFAULT_MEMBER\n              : VmReferenceAccessErrorType.CANNOT_FIND_MEMBER;\n      throw new VmReferenceAccessError(type, errorType);\n    }\n    var baseModule = BaseModule.getModuleClass().export();\n    // restriction: cannot reference Module.output.\n    //   generalized: properties originally defined in external classes; the only extant example.\n    // This is implemented specifically because this is the only case where an external class\n    //   containing a property can be subclassed.\n    // And this can't check prop.getOwner().isExternal() because fully overriding the property with\n    //   a new type annotation means the owner isn't Module.\n    if (clazz.getPClass().isSubclassOf(baseModule) && property.equals(\"output\")) {\n      throw new VmReferenceAccessError(\n          new PType.Class(baseModule), VmReferenceAccessErrorType.EXTERNAL_CLASS);\n    }\n\n    // dot access on `Reference<D, Null>` gives `Reference<D, Null>`\n    if (clazz.getPClass().getInfo() == PClassInfo.Null) {\n      result.add(clazz);\n      return;\n    }\n\n    var prop = clazz.getPClass().getAllProperties().get(property);\n    if (prop == null) {\n      throw new VmReferenceAccessError(type, VmReferenceAccessErrorType.CANNOT_FIND_MEMBER);\n    }\n\n    // restriction: cannot reference external properties\n    if (prop.isExternal()) {\n      throw new VmReferenceAccessError(type, VmReferenceAccessErrorType.EXTERNAL_MEMBER);\n    }","sourceCodeStart":225,"sourceCodeEnd":261,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/runtime/VmReference.java#L225-L261","documentation":"Raised when code references the `output` property of a Module through the Reference property-type machinery. Module.output is defined in an external (base) class, and Pkl forbids referencing properties originally defined in external classes — the only such subclassable case being Module.output.","triggerScenarios":"Referencing `someModule.output` in a context validated by getCandidatePropertyType (e.g. property type references in amends/extends scenarios).","commonSituations":"Trying to read another module's rendered output inside Pkl; using `output` in type positions or reference-checking paths rather than through normal evaluation.","solutions":["Avoid referencing `module.output` inside Pkl; output is meant for the host/consumer.","Expose the needed data as a regular (non-output) property on the module.","If you need the rendered text, evaluate and export from the host side instead.","Move the data out of `output` into a named property that reference-checking allows."],"exampleFix":"// before\nx = MyModule.output\n// after (in MyModule)\nrendered = \"...\" // regular property\n// then\nx = MyModule.rendered","handlingStrategy":"validation","validationCode":"// Pkl: ensure you never reference Module.output in reference positions\n// expose data as a normal property instead\nrendered = \"...\"","typeGuard":null,"tryCatchPattern":"try {\n  eval(src);\n} catch (EvalException e) {\n  if (e.getMessage().contains(\"externalClass\")) {\n    // you referenced a property from an external class (e.g. Module.output)\n  }\n}","preventionTips":["Treat `output` as write-only from Pkl's perspective; consume it from the host.","Duplicate needed output content into a regular property for internal references.","Avoid building abstractions that read other modules' output."],"tags":["pkl","module","output","external-class"],"backgroundTag":"external-member-access","analyzedSha":"f3efcbfc9b60d30053b0536d664948d7aa1b8673","analyzedAt":"2026-09-08T13:10:45.570Z","contentChangedAt":"2026-09-08T13:10:45.570Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}