Fix checking of subscript key types references to Map/Mapping (#1933)

This commit is contained in:
Jen Basch authored and GitHub committed 2026-10-22 17:01:46 +00:00
1 parent dd026c7023
commit 05d8e88592
3 files changed
+12 -1

No files matched your search

@@ -297,7 +297,8 @@ public final class VmReference extends VmValue {
var keyTypes = normalizeTypes(typeArgs[0], clazz, clazz.getModuleClass());
for (var kt : iterateTypes(keyTypes)) {
if (kt == UnknownType.INSTANCE
|| (kt instanceof VmType.ClassType klazz && klazz.getVmClass() == VmUtils.getClass(key))
|| (kt instanceof VmType.ClassType klazz
&& klazz.getVmClass().isSuperclassOf(VmUtils.getClass(key)))
|| (kt instanceof VmType.StringLiteralType stringLiteral
&& stringLiteral.getLiteral().equals(key))) {
normalizeTypes(typeArgs[1], clazz, clazz.getModuleClass(), result);
@@ -125,6 +125,8 @@ aValuesJoined = k.aValues.join("\n")
typeArgs = ref.Reference(d, TypeHolder, null).prop as Ref<Listing<Number | Boolean | String>>
class TypeHolder {
prop: Listing<String | Boolean | Number>
mappingAnyKey: Mapping<Any, Int>
mappingTypeArgKey: Mapping<Listing<Int>, Int>
}
class BadResource extends Resource {
@@ -137,6 +139,12 @@ badThisRef = test.catch(() -> new BadResource { name = "bad" }.$.toString())
// test that a bare function type toStrings/exports okay
bareFunctionType = test.catch(() -> ref.Reference(d, Function4, null) as Ref<String>)
mappingAnyKey = ref.Reference(d, TypeHolder, null).mappingAnyKey["foo"]
// this one should be an editor error but can't be caught in the runtime
// because VmListing/VmMapping don't track their type args
mappingTypeArgKey = ref.Reference(d, TypeHolder, null).mappingTypeArgKey[new Listing<String> { "foo" }]
output {
renderer {
converters {
@@ -62,3 +62,5 @@ aValuesJoined = """
typeArgs = "${null.prop}"
badThisRef = "Expected value of type `pkl.ref#Reference<reference#D, this>`, but got type `pkl.ref#Reference<reference#D, reference#A>`. Value: Reference(new reference#D {}, reference#A, new reference#BadResource { name =..."
bareFunctionType = "Expected value of type `pkl.ref#Reference<reference#D, String>`, but got type `pkl.ref#Reference<reference#D, Function4>`. Value: Reference(new reference#D {}, Function4, null)"
mappingAnyKey = "${null.mappingAnyKey[foo]}"
mappingTypeArgKey = "${null.mappingTypeArgKey[new Listing { \"foo\" }]}"