mirror of
https://github.com/apple/pkl.git
synced 2026-08-26 21:54:03 +02:00
Fix reflect crash on modules using glob imports (#1816)
This excludes glob imports when creating a module's mirror
This commit is contained in:
@@ -115,7 +115,11 @@ public final class VmTyped extends VmObject {
|
|||||||
if (bodyNode instanceof WrapperNode wrapper) {
|
if (bodyNode instanceof WrapperNode wrapper) {
|
||||||
bodyNode = (ExpressionNode) wrapper.getDelegateNode();
|
bodyNode = (ExpressionNode) wrapper.getDelegateNode();
|
||||||
}
|
}
|
||||||
builder.add(member.getName().toString(), ((ImportNode) bodyNode).getImportUri().toString());
|
// Glob imports (`import*`) don't import a type; they resolve to a mapping.
|
||||||
|
// Exclude them here, consistent with `imports` also not covering import expressions.
|
||||||
|
if (bodyNode instanceof ImportNode importNode) {
|
||||||
|
builder.add(member.getName().toString(), importNode.getImportUri().toString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return builder.build();
|
return builder.build();
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
import "pkl:reflect"
|
||||||
|
import* "../../input-helper/globtest/child/*.pkl" as globbed
|
||||||
|
|
||||||
|
// regression test for VmTyped.getImports()
|
||||||
|
// `member.isImport()` is true for glob imports too, so reflecting a module that
|
||||||
|
// uses `import*` previously threw ClassCastException when casting the glob
|
||||||
|
// import's body to ImportNode.
|
||||||
|
// Glob imports resolve to a mapping rather than a module type, so they are
|
||||||
|
// excluded from `imports` (which only reports regular imports).
|
||||||
|
res = reflect.Module(module).imports
|
||||||
|
|
||||||
|
// the glob import itself still works
|
||||||
|
globbedKeys = globbed.keys.toListing()
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
res = Map("reflect", "pkl:reflect")
|
||||||
|
globbedKeys {
|
||||||
|
"../../input-helper/globtest/child/moduleC.pkl"
|
||||||
|
}
|
||||||
+1
-1
@@ -201,7 +201,7 @@ external class Module extends Declaration {
|
|||||||
/// Map keys are the identifiers by which imports are accessed within this module.
|
/// Map keys are the identifiers by which imports are accessed within this module.
|
||||||
/// Map values are the URIs of the imported modules.
|
/// Map values are the URIs of the imported modules.
|
||||||
///
|
///
|
||||||
/// Does not cover import expressions.
|
/// Does not cover import expressions or glob imports.
|
||||||
imports: Map<String, Uri>
|
imports: Map<String, Uri>
|
||||||
|
|
||||||
/// The classes declared in this module.
|
/// The classes declared in this module.
|
||||||
|
|||||||
Reference in New Issue
Block a user