Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,10 @@ public AstBuilder(
isMethodReturnTypeChecked = !isStdLibModule || IoUtils.isTestMode();
}

public ModuleInfo getModuleInfo() {
return moduleInfo;
}

public static AstBuilder create(
Source source,
VmLanguage language,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ public VmClass executeGeneric(VirtualFrame frame) {
// nodes
// via static final fields without having to fear recursive field initialization.
prototype = module;
prototype.setExtraStorage(moduleInfo);
// Only set ModuleInfo if it hasn't been set already (to handle cyclic dependencies)
if (!prototype.hasExtraStorage()) {
prototype.setExtraStorage(moduleInfo);
}
prototype.addProperties(prototypeMembers);
} else {
prototype =
Expand Down
5 changes: 5 additions & 0 deletions pkl-core/src/main/java/org/pkl/core/runtime/VmLanguage.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ void initializeModule(
var builder =
AstBuilder.create(
source, this, moduleContext, moduleKey, resolvedModuleKey, moduleResolver);

// Set the ModuleInfo on the empty module immediately to handle cyclic dependencies.
// This ensures it works even if the module is accessed during initialization via imports
emptyModule.setExtraStorage(builder.getModuleInfo());

var moduleNode = builder.visitModule(moduleContext);
moduleNode.getCallTarget().call(emptyModule, emptyModule);
MinPklVersionChecker.check(emptyModule, importNode);
Expand Down