Enforce stricter rules on reference access (#1718)

This changes the following:

1. If given a union type, the member must exist on each member of that type
2. If accessing a member off `Reference<D, Null>`, give a `Reference<D, Null>`

Also:
* Improve error messages thrown during member access.
* Add test around accessing members off of a function type
This commit is contained in:
Daniel Chao
2026-07-06 19:24:14 -07:00
committed by GitHub
parent 3fc97d8dad
commit 2ec62c99a7
28 changed files with 339 additions and 70 deletions
@@ -23,7 +23,11 @@ import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.nodes.IndirectCallNode; import com.oracle.truffle.api.nodes.IndirectCallNode;
import com.oracle.truffle.api.nodes.NodeInfo; import com.oracle.truffle.api.nodes.NodeInfo;
import com.oracle.truffle.api.source.SourceSection; import com.oracle.truffle.api.source.SourceSection;
import org.jspecify.annotations.Nullable;
import org.pkl.core.runtime.*; import org.pkl.core.runtime.*;
import org.pkl.core.runtime.VmReference.VmReferenceAccessError;
import org.pkl.core.runtime.VmReference.VmReferenceAccessErrorType;
import org.pkl.core.util.ErrorMessages;
@NodeInfo(shortName = "[]") @NodeInfo(shortName = "[]")
public abstract class SubscriptNode extends BinaryExpressionNode { public abstract class SubscriptNode extends BinaryExpressionNode {
@@ -100,18 +104,32 @@ public abstract class SubscriptNode extends BinaryExpressionNode {
return readMember(dynamic, key, callNode); return readMember(dynamic, key, callNode);
} }
private @Nullable String getReferenceHint(
VmReference reference, VmReferenceAccessError err, Object key) {
var myType = reference.getReferentType();
if (err.getErrorType() != VmReferenceAccessErrorType.CANNOT_FIND_MEMBER) {
return null;
}
return err.getType().equals(myType)
? ErrorMessages.create("operatorNotDefined2", getShortName(), myType, VmUtils.getClass(key))
: ErrorMessages.create(
"operatorNotDefined3", getShortName(), myType, err.getType(), VmUtils.getClass(key));
}
@Specialization @Specialization
protected VmReference eval(VmReference reference, Object key) { protected VmReference eval(VmReference reference, Object key) {
var result = reference.withSubscriptAccess(key); try {
if (result != null) return result; return reference.withSubscriptAccess(key);
} catch (VmReferenceAccessError err) {
CompilerDirectives.transferToInterpreter(); CompilerDirectives.transferToInterpreter();
throw exceptionBuilder() throw exceptionBuilder()
.evalError( .evalError(
"operatorNotDefined2", getShortName(), reference.exportType(), VmUtils.getClass(key)) "operatorNotDefined2", getShortName(), reference.exportType(), VmUtils.getClass(key))
.withProgramValue("Left operand", reference) .withProgramValue("Left operand", reference)
.withProgramValue("Right operand", key) .withProgramValue("Right operand", key)
.build(); .withHint(getReferenceHint(reference, err, key))
.build();
}
} }
@Specialization @Specialization
@@ -24,10 +24,13 @@ import com.oracle.truffle.api.nodes.IndirectCallNode;
import com.oracle.truffle.api.nodes.NodeInfo; import com.oracle.truffle.api.nodes.NodeInfo;
import com.oracle.truffle.api.source.SourceSection; import com.oracle.truffle.api.source.SourceSection;
import org.jspecify.annotations.Nullable; import org.jspecify.annotations.Nullable;
import org.pkl.core.PType;
import org.pkl.core.ast.ExpressionNode; import org.pkl.core.ast.ExpressionNode;
import org.pkl.core.ast.MemberLookupMode; import org.pkl.core.ast.MemberLookupMode;
import org.pkl.core.ast.member.ClassProperty; import org.pkl.core.ast.member.ClassProperty;
import org.pkl.core.runtime.*; import org.pkl.core.runtime.*;
import org.pkl.core.runtime.VmReference.VmReferenceAccessError;
import org.pkl.core.util.ErrorMessages;
@NodeInfo(shortName = ".") @NodeInfo(shortName = ".")
@ImportStatic(BaseModule.class) @ImportStatic(BaseModule.class)
@@ -61,16 +64,38 @@ public abstract class ReadPropertyNode extends ExpressionNode {
this(sourceSection, propertyName, MemberLookupMode.EXPLICIT_RECEIVER, false); this(sourceSection, propertyName, MemberLookupMode.EXPLICIT_RECEIVER, false);
} }
protected String getReferenceErrorHint(VmReference reference, VmReferenceAccessError err) {
var myType = reference.getReferentType();
return switch (err.getErrorType()) {
case CANNOT_FIND_MEMBER ->
err.getType().equals(myType)
? ErrorMessages.create("cannotFindPropertyInType", propertyName, myType)
: ErrorMessages.create(
"cannotFindPropertyInType2", propertyName, myType, err.getType());
case EXTERNAL_MEMBER ->
ErrorMessages.create("cannotReferenceExternalProperty", propertyName, err.getType());
case DEFAULT_MEMBER ->
ErrorMessages.create(
"cannotReferenceDefaultProperty",
((PType.Class) err.getType()).getPClass().getSimpleName());
case EXTERNAL_CLASS ->
ErrorMessages.create(
"cannotReferencePropertyInExternalClass", propertyName, err.getType());
};
}
@Specialization @Specialization
protected VmReference evalReference(VmReference receiver) { protected VmReference evalReference(VmReference receiver) {
assert lookupMode == MemberLookupMode.EXPLICIT_RECEIVER; assert lookupMode == MemberLookupMode.EXPLICIT_RECEIVER;
var result = receiver.withPropertyAccess(propertyName); try {
if (result != null) return result; return receiver.withPropertyAccess(propertyName);
} catch (VmReferenceAccessError err) {
CompilerDirectives.transferToInterpreter(); CompilerDirectives.transferToInterpreter();
throw exceptionBuilder() throw exceptionBuilder()
.evalError("cannotFindPropertyInReference", propertyName, receiver.exportType()) .evalError("cannotFindPropertyInObjectNoHint", propertyName, receiver.exportType())
.build(); .withHint(getReferenceErrorHint(receiver, err))
.build();
}
} }
// This method effectively covers `VmObject receiver` but is implemented in a more // This method effectively covers `VmObject receiver` but is implemented in a more
@@ -42,7 +42,8 @@ public final class VmReference extends VmValue {
private final Object data; private final Object data;
private final ImRrbt<VmTyped> path; private final ImRrbt<VmTyped> path;
// candidate types can only be: PType.Class, PType.Alias (only preservedAliasTypes), // candidate types can only be: PType.Class, PType.Alias (only preservedAliasTypes),
// PType.StringLiteral, PType.UNKNOWN, or PType.Union (containing only the previous; flattened) // PType.StringLiteral, PType.UNKNOWN, PType.Function, PType.TypeVariable, or PType.Union
// (containing only the previous; flattened)
private final PType referentType; private final PType referentType;
private boolean forced = false; private boolean forced = false;
@@ -131,9 +132,12 @@ public final class VmReference extends VmValue {
} }
result.add(new PType.Class(clazz.getPClass(), typeArgs)); result.add(new PType.Class(clazz.getPClass(), typeArgs));
} }
} else if (type instanceof PType.Nullable nullable) { }
// normalize `T?` to `T | Null`
else if (type instanceof PType.Nullable nullable) {
normalizeTypes(nullable.getBaseType(), moduleClass, result); normalizeTypes(nullable.getBaseType(), moduleClass, result);
result.add(new PType.Class(BaseModule.getNullClass().export())); result.add(new PType.Class(BaseModule.getNullClass().export()));
// erase `T(someConstraint)` to `T`
} else if (type instanceof PType.Constrained constrained) { } else if (type instanceof PType.Constrained constrained) {
normalizeTypes(constrained.getBaseType(), moduleClass, result); normalizeTypes(constrained.getBaseType(), moduleClass, result);
} else if (type instanceof PType.Alias alias) { } else if (type instanceof PType.Alias alias) {
@@ -148,6 +152,11 @@ public final class VmReference extends VmValue {
} }
} else if (type == PType.MODULE) { } else if (type == PType.MODULE) {
result.add(new PType.Class(moduleClass)); result.add(new PType.Class(moduleClass));
} else {
// remaining types: PType.Function, PType.TypeVariable. no normalizing needed; TypeVariable
// gets replaced upon instantiation, and Function can bubble up to users as a reference error
// if accessed.
result.add(type);
} }
} }
@@ -156,29 +165,26 @@ public final class VmReference extends VmValue {
return Collections.singleton(t); return Collections.singleton(t);
} }
public @Nullable VmReference withPropertyAccess(Identifier property) { public VmReference withPropertyAccess(Identifier property) {
var propString = property.toString(); var propString = property.toString();
return withAccess( return withAccess(
(t, candidates) -> getCandidatePropertyType(t, propString, candidates), (t, candidates) -> getCandidatePropertyType(t, propString, candidates),
() -> newAccess(property.toString(), null)); () -> newAccess(property.toString(), null));
} }
public @Nullable VmReference withSubscriptAccess(Object key) { public VmReference withSubscriptAccess(Object key) {
return withAccess( return withAccess(
(t, candidates) -> getCandidateSubscriptType(t, key, candidates), (t, candidates) -> getCandidateSubscriptType(t, key, candidates),
() -> newAccess(null, key)); () -> newAccess(null, key));
} }
@TruffleBoundary @TruffleBoundary
private @Nullable VmReference withAccess( private VmReference withAccess(
BiConsumer<PType, Set<PType>> checkCandidate, Supplier<VmTyped> makeAccess) { BiConsumer<PType, Set<PType>> checkCandidate, Supplier<VmTyped> makeAccess) {
Set<PType> candidates = new HashSet<>(); Set<PType> candidates = new HashSet<>();
for (var t : iterateTypes(referentType)) { for (var t : iterateTypes(referentType)) {
checkCandidate.accept(t, candidates); checkCandidate.accept(t, candidates);
} }
if (candidates.isEmpty()) {
return null; // no valid access found
}
return new VmReference(domain, data, path.append(makeAccess.get()), minimizeTypes(candidates)); return new VmReference(domain, data, path.append(makeAccess.get()), minimizeTypes(candidates));
} }
@@ -189,33 +195,54 @@ public final class VmReference extends VmValue {
return; return;
} }
// restriction: only class types can have their properties referenced // restriction: only class types can have their properties referenced
if (!(type instanceof PType.Class clazz)) return; if (!(type instanceof PType.Class clazz)) {
// restriction: cannot reference properties of external classes throw new VmReferenceAccessError(type, VmReferenceAccessErrorType.CANNOT_FIND_MEMBER);
if (clazz.getPClass().isExternal()) return; }
if (clazz.getPClass().getInfo() == PClassInfo.Dynamic) { if (clazz.getPClass().getInfo() == PClassInfo.Dynamic) {
// restriction: cannot reference Dynamic.default if (property.equals("default")) {
if (!property.equals("default")) result.add(PType.UNKNOWN); // restriction: cannot reference Dynamic.default
throw new VmReferenceAccessError(type, VmReferenceAccessErrorType.DEFAULT_MEMBER);
}
result.add(PType.UNKNOWN);
return; return;
} }
// restriction: cannot reference Listing/Mapping.default // restriction: cannot reference Listing/Mapping.default
if (clazz.getPClass().getInfo() == PClassInfo.Listing if (clazz.getPClass().getInfo() == PClassInfo.Listing
|| clazz.getPClass().getInfo() == PClassInfo.Mapping) { || clazz.getPClass().getInfo() == PClassInfo.Mapping) {
return; var errorType =
property.equals("default")
? VmReferenceAccessErrorType.DEFAULT_MEMBER
: VmReferenceAccessErrorType.CANNOT_FIND_MEMBER;
throw new VmReferenceAccessError(type, errorType);
} }
var baseModule = BaseModule.getModuleClass().export();
// restriction: cannot reference Module.output. // restriction: cannot reference Module.output.
// generalized: properties originally defined in external classes; the only extant example. // generalized: properties originally defined in external classes; the only extant example.
// This is implemented specifically because this is the only case where an external class // This is implemented specifically because this is the only case where an external class
// containing a property can be subclassed. // containing a property can be subclassed.
// And this can't check prop.getOwner().isExternal() because fully overriding the property with // And this can't check prop.getOwner().isExternal() because fully overriding the property with
// a new type annotation means the owner isn't Module. // a new type annotation means the owner isn't Module.
if (clazz.getPClass().isSubclassOf(BaseModule.getModuleClass().export()) if (clazz.getPClass().isSubclassOf(baseModule) && property.equals("output")) {
&& property.equals("output")) return; throw new VmReferenceAccessError(
new PType.Class(baseModule), VmReferenceAccessErrorType.EXTERNAL_CLASS);
}
var prop = clazz.getPClass().getAllProperties().get(property); // dot access on `Reference<D, Null>` gives `Reference<D, Null>`
// restriction: cannot reference external properties if (clazz.getPClass().getInfo() == PClassInfo.Null) {
if (prop == null || prop.isExternal()) { result.add(clazz);
return; return;
} }
var prop = clazz.getPClass().getAllProperties().get(property);
if (prop == null) {
throw new VmReferenceAccessError(type, VmReferenceAccessErrorType.CANNOT_FIND_MEMBER);
}
// restriction: cannot reference external properties
if (prop.isExternal()) {
throw new VmReferenceAccessError(type, VmReferenceAccessErrorType.EXTERNAL_MEMBER);
}
normalizeTypes(prop.getType(), clazz.getPClass().getModuleClass(), result); normalizeTypes(prop.getType(), clazz.getPClass().getModuleClass(), result);
} }
@@ -235,7 +262,7 @@ public final class VmReference extends VmValue {
return; return;
} }
if (!(type instanceof PType.Class clazz)) { if (!(type instanceof PType.Class clazz)) {
return; throw new VmReferenceAccessError(type, VmReferenceAccessErrorType.CANNOT_FIND_MEMBER);
} }
if (clazz.getPClass().getInfo() == PClassInfo.Dynamic) { if (clazz.getPClass().getInfo() == PClassInfo.Dynamic) {
result.add(PType.UNKNOWN); result.add(PType.UNKNOWN);
@@ -243,9 +270,10 @@ public final class VmReference extends VmValue {
} }
if (clazz.getPClass().getInfo() == PClassInfo.Listing if (clazz.getPClass().getInfo() == PClassInfo.Listing
|| clazz.getPClass().getInfo() == PClassInfo.List) { || clazz.getPClass().getInfo() == PClassInfo.List) {
if (key instanceof Long) { if (!(key instanceof Long)) {
normalizeTypes(clazz.getTypeArguments().get(0), clazz.getPClass().getModuleClass(), result); throw new VmReferenceAccessError(type, VmReferenceAccessErrorType.CANNOT_FIND_MEMBER);
} }
normalizeTypes(clazz.getTypeArguments().get(0), clazz.getPClass().getModuleClass(), result);
return; return;
} }
if (clazz.getPClass().getInfo() == PClassInfo.Mapping if (clazz.getPClass().getInfo() == PClassInfo.Mapping
@@ -262,6 +290,14 @@ public final class VmReference extends VmValue {
} }
} }
} }
// subscript access on `Reference<D, Null>` gives `Reference<D, Null>`
if (clazz.getPClass().getInfo() == PClassInfo.Null) {
result.add(clazz);
return;
}
throw new VmReferenceAccessError(type, VmReferenceAccessErrorType.CANNOT_FIND_MEMBER);
} }
/** /**
@@ -490,4 +526,29 @@ public final class VmReference extends VmValue {
var callNode = DirectCallNode.create(toStringMethod.getCallTarget()); var callNode = DirectCallNode.create(toStringMethod.getCallTarget());
return (String) callNode.call(this, getVmClass().getPrototype()); return (String) callNode.call(this, getVmClass().getPrototype());
} }
public enum VmReferenceAccessErrorType {
CANNOT_FIND_MEMBER,
EXTERNAL_MEMBER,
DEFAULT_MEMBER,
EXTERNAL_CLASS
}
public static final class VmReferenceAccessError extends RuntimeException {
private final PType type;
private final VmReferenceAccessErrorType errorType;
public VmReferenceAccessError(PType type, VmReferenceAccessErrorType errorType) {
this.type = type;
this.errorType = errorType;
}
public PType getType() {
return type;
}
public VmReferenceAccessErrorType getErrorType() {
return errorType;
}
}
} }
@@ -319,6 +319,10 @@ Operator `{0}` is not defined for operand type `{1}`.
operatorNotDefined2=\ operatorNotDefined2=\
Operator `{0}` is not defined for operand types `{1}` and `{2}`. Operator `{0}` is not defined for operand types `{1}` and `{2}`.
operatorNotDefined3=\
Operator `{0}` is not defined for operand types `{1}` and `{3}`.\n\
\t└─ Operator `{0}` is not defined for operand types `{2}` and `{3}`.
operatorNotDefinedLeft=\ operatorNotDefinedLeft=\
Operator `{0}` is not defined for left operand type `{1}`. Operator `{0}` is not defined for left operand type `{1}`.
@@ -388,9 +392,25 @@ Cannot find property `{0}` in object of type `{1}`.\n\
Did you mean any of the following?\n\ Did you mean any of the following?\n\
{2} {2}
cannotFindPropertyInReference=\ cannotFindPropertyInObjectNoHint=\
Cannot find property `{0}` in object of type `{1}`. Cannot find property `{0}` in object of type `{1}`.
cannotFindPropertyInType=\
Cannot find property `{0}` in type `{1}`.
cannotFindPropertyInType2=\
Cannot find property `{0}` in type `{1}`.\n\
\t└─ Cannot find property `{0}` in type `{2}`.
cannotReferenceExternalProperty=\
Cannot reference external property `{0}` in class `{1}`.
cannotReferenceDefaultProperty=\
Cannot reference property `default` in class `{0}`.
cannotReferencePropertyInExternalClass=\
Cannot reference property `{0}` because it is defined inside external class `{1}`.
cannotFindMethodInScope=\ cannotFindMethodInScope=\
Cannot find method `{0}`. Cannot find method `{0}`.
@@ -36,6 +36,7 @@ class AProperties {
someListing: Listing<Int> someListing: Listing<Int>
someList: List<Int> someList: List<Int>
nonInt: String nonInt: String
nullProp: Null
} }
class B extends Resource { class B extends Resource {
@@ -64,6 +65,7 @@ class K {
bId: String | *Ref<String>? bId: String | *Ref<String>?
aProperties: AProperties | *Ref<AProperties>? aProperties: AProperties | *Ref<AProperties>?
bProperties: BProperties | *Ref<BProperties>? bProperties: BProperties | *Ref<BProperties>?
nullProp: Ref<Null>?
aValues: Listing<Int | Ref<Int?>>? aValues: Listing<Int | Ref<Int?>>?
bValues: Listing<String | Ref<String?>>? bValues: Listing<String | Ref<String?>>?
splitUnion: Ref<Listing<String> | Listing<Int>>? splitUnion: Ref<Listing<String> | Listing<Int>>?
@@ -91,6 +93,7 @@ k: K = new {
bId = bRef.id bId = bRef.id
aProperties = aRef.outputs aProperties = aRef.outputs
bProperties = bRef.outputs bProperties = bRef.outputs
nullProp = aRef.outputs.nullProp.prop1.prop2["foo"].prop3
aValues { aValues {
aRef.outputs.foo aRef.outputs.foo
aRef.outputs.someMapping["key"] aRef.outputs.someMapping["key"]
@@ -17,39 +17,40 @@ local class Holder {
optional: Mapping<String, Int?> optional: Mapping<String, Int?>
listing: Listing<Int> listing: Listing<Int>
union: Listing<String> | Listing<Int> union: Listing<String> | Listing<Int>
constrainedType: String(isEmpty)
} }
local const h: Holder = new { local class OtherHolder {
num = 1 num: Int?
text = "t" constrainedType: String(isEmpty)
lit = "literal"
small = 8
optional { ["k"] = 5 }
listing { 1; 2 }
union = new Listing<Int> { 1 }
} }
local hRef1: Ref<Holder> = ref.Reference(d, Holder, h) local holderRef: Ref<Holder> = ref.Reference(d, Holder, null)
local hRef2: Ref<Holder> = ref.Reference(d, Holder, h) local holderRef2: Ref<Holder> = ref.Reference(d, Holder, null)
local otherHolderRef: Ref<OtherHolder> = ref.Reference(d, OtherHolder, null)
facts { facts {
["equality"] { ["equality"] {
hRef1 == hRef2 holderRef == holderRef2
hRef1.num == hRef2.num holderRef.num == holderRef2.num
hRef1.lit == hRef2.lit holderRef.lit == holderRef2.lit
hRef1.small == hRef2.small holderRef.small == holderRef2.small
hRef1.optional["k"] == hRef2.optional["k"] holderRef.optional["k"] == holderRef2.optional["k"]
hRef1.listing[0] == hRef2.listing[0] holderRef.listing[0] == holderRef2.listing[0]
hRef1.union == hRef2.union holderRef.union == holderRef2.union
}
["equality -- constraint gets erased"] {
holderRef.constrainedType == otherHolderRef.constrainedType
} }
["inequality"] { ["inequality"] {
hRef1.num != hRef2.text holderRef.num != holderRef2.text
} }
["set deduplication"] { ["set deduplication"] {
Set(hRef1.num, hRef2.num).length == 1 Set(holderRef.num, holderRef2.num).length == 1
Set(hRef1.union, hRef2.union).length == 1 Set(holderRef.union, holderRef2.union).length == 1
Set(hRef1.num, hRef2.text).length == 2 Set(holderRef.num, holderRef2.text).length == 2
} }
} }
@@ -6,7 +6,7 @@ class D extends ref.Domain {
typealias Ref<T> = ref.Reference<D, T> typealias Ref<T> = ref.Reference<D, T>
local d: D = new {} local d: D = new {}
test = ref.Reference(d, String, "") as Ref<Alias1?> test = ref.Reference(d, String, "") as Ref<Alias1>
typealias Alias1 = Int | Alias2? typealias Alias1 = Int | Alias2
typealias Alias2 = String(length < 5) typealias Alias2 = String(length < 5)
@@ -0,0 +1,17 @@
import "pkl:ref"
class D extends ref.Domain {
function renderReference(_): String = throw("not implemented")
}
class Bird {
name: String
}
class Holder {
$: Bird | Int
}
myRef: ref.Reference<D, Bird | Int> = ref.Reference(new D {}, Holder, null).$
res = myRef.name
@@ -0,0 +1,13 @@
import "pkl:ref"
class D extends ref.Domain {
function renderReference(_): String = throw("not implemented")
}
class Holder {
$: Duration | Listing<String>
}
local myRef = ref.Reference(new D {}, Holder, null).$
res = myRef[0]
@@ -0,0 +1,9 @@
import "pkl:ref"
class D extends ref.Domain {
function renderReference(_): String = throw("not implemented")
}
local myRef = ref.Reference(new D {}, Listing, null)
res = myRef.name
@@ -0,0 +1,13 @@
import "pkl:ref"
class D extends ref.Domain {
function renderReference(_): String = throw("not implemented")
}
class Holder {
func: (Int) -> Boolean
}
local myRef = ref.Reference(new D {}, Holder, null).func
res = myRef.name
@@ -6,7 +6,7 @@ class D extends ref.Domain {
local d: D = new {} local d: D = new {}
typealias Ref<T> = ref.Reference<D, T> typealias Ref<T> = ref.Reference<D, T>
test = ref.Reference(d, String, "") as Ref<Alias1?> test = ref.Reference(d, String, "") as Ref<Alias1>
typealias Alias1 = Int | Alias2? typealias Alias1 = Int | Alias2
typealias Alias2 = Boolean typealias Alias2 = Boolean
@@ -20,6 +20,7 @@ k {
bId = "${b.id}" bId = "${b.id}"
aProperties = "${a.outputs}" aProperties = "${a.outputs}"
bProperties = "${b.outputs}" bProperties = "${b.outputs}"
nullProp = "${a.outputs.nullProp.prop1.prop2[foo].prop3}"
aValues { aValues {
"${a.outputs.foo}" "${a.outputs.foo}"
"${a.outputs.someMapping[key]}" "${a.outputs.someMapping[key]}"
@@ -43,12 +44,13 @@ j {
bId = null bId = null
aProperties = "${a.outputs}" aProperties = "${a.outputs}"
bProperties = null bProperties = null
nullProp = null
aValues = null aValues = null
bValues = null bValues = null
splitUnion = "${a.outputs.someListing}" splitUnion = "${a.outputs.someListing}"
} }
refInterpolation = "${a.outputs.someListing[1]}" refInterpolation = "${a.outputs.someListing[1]}"
kInterpolation = "new K { aId = Reference(new D {}, String, new A { name = \"a\"; id = \"some-a-value\" }).id; bId = Reference(new D {}, String, new B { name = \"b\"; id = \"some-b-value\" }).id; aProperties = Reference(new D {}, reference#AProperties, new A { name = \"a\"; id = \"some-a-value\" }).outputs; bProperties = Reference(new D {}, reference#BProperties, new B { name = \"b\"; id = \"some-b-value\" }).outputs; aValues { Reference(new D {}, Int, new A { name = \"a\"; id = \"some-a-value\" }).outputs.foo; Reference(new D {}, Int | Null, new A { name = \"a\"; id = \"some-a-value\" }).outputs.someMapping[\"key\"]; Reference(new D {}, Int, new A { name = \"a\"; id = \"some-a-value\" }).outputs.someMap[new MapKey { k = 123 }]; Reference(new D {}, Int, new A { name = \"a\"; id = \"some-a-value\" }).outputs.someListing[0]; Reference(new D {}, Int, new A { name = \"a\"; id = \"some-a-value\" }).outputs.someList[9223372036854775807]; Reference(new D {}, Int, new B { name = \"b\"; id = \"some-b-value\" }).outputs.nonString }; bValues { Reference(new D {}, String, new B { name = \"b\"; id = \"some-b-value\" }).outputs.foo; Reference(new D {}, Null | String, new B { name = \"b\"; id = \"some-b-value\" }).outputs.someMapping[\"key\"]; Reference(new D {}, String, new B { name = \"b\"; id = \"some-b-value\" }).outputs.someMap[new MapKey { k = 123 }]; Reference(new D {}, String, new B { name = \"b\"; id = \"some-b-value\" }).outputs.someListing[0]; Reference(new D {}, String, new B { name = \"b\"; id = \"some-b-value\" }).outputs.someList[9223372036854775807]; Reference(new D {}, String, new A { name = \"a\"; id = \"some-a-value\" }).outputs.nonInt }; splitUnion = null }" kInterpolation = "new K { aId = Reference(new D {}, String, new A { name = \"a\"; id = \"some-a-value\" }).id; bId = Reference(new D {}, String, new B { name = \"b\"; id = \"some-b-value\" }).id; aProperties = Reference(new D {}, reference#AProperties, new A { name = \"a\"; id = \"some-a-value\" }).outputs; bProperties = Reference(new D {}, reference#BProperties, new B { name = \"b\"; id = \"some-b-value\" }).outputs; nullProp = Reference(new D {}, Null, new A { name = \"a\"; id = \"some-a-value\" }).outputs.nullProp.prop1.prop2[\"foo\"].prop3; aValues { Reference(new D {}, Int, new A { name = \"a\"; id = \"some-a-value\" }).outputs.foo; Reference(new D {}, Int | Null, new A { name = \"a\"; id = \"some-a-value\" }).outputs.someMapping[\"key\"]; Reference(new D {}, Int, new A { name = \"a\"; id = \"some-a-value\" }).outputs.someMap[new MapKey { k = 123 }]; Reference(new D {}, Int, new A { name = \"a\"; id = \"some-a-value\" }).outputs.someListing[0]; Reference(new D {}, Int, new A { name = \"a\"; id = \"some-a-value\" }).outputs.someList[9223372036854775807]; Reference(new D {}, Int, new B { name = \"b\"; id = \"some-b-value\" }).outputs.nonString }; bValues { Reference(new D {}, String, new B { name = \"b\"; id = \"some-b-value\" }).outputs.foo; Reference(new D {}, Null | String, new B { name = \"b\"; id = \"some-b-value\" }).outputs.someMapping[\"key\"]; Reference(new D {}, String, new B { name = \"b\"; id = \"some-b-value\" }).outputs.someMap[new MapKey { k = 123 }]; Reference(new D {}, String, new B { name = \"b\"; id = \"some-b-value\" }).outputs.someListing[0]; Reference(new D {}, String, new B { name = \"b\"; id = \"some-b-value\" }).outputs.someList[9223372036854775807]; Reference(new D {}, String, new A { name = \"a\"; id = \"some-a-value\" }).outputs.nonInt }; splitUnion = null }"
aValuesJoined = """ aValuesJoined = """
${a.outputs.foo} ${a.outputs.foo}
${a.outputs.someMapping[key]} ${a.outputs.someMapping[key]}
@@ -8,6 +8,9 @@ facts {
true true
true true
} }
["equality -- constraint gets erased"] {
true
}
["inequality"] { ["inequality"] {
true true
} }
@@ -5,7 +5,7 @@ xx | typealias Alias2 = String(length < 5)
^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^
at reference11#Alias2 (file:///$snippetsDir/input/errors/reference11.pkl) at reference11#Alias2 (file:///$snippetsDir/input/errors/reference11.pkl)
xx | typealias Alias1 = Int | Alias2? xx | typealias Alias1 = Int | Alias2
^^^^^^ ^^^^^^
at reference11#Alias1 (file:///$snippetsDir/input/errors/reference11.pkl) at reference11#Alias1 (file:///$snippetsDir/input/errors/reference11.pkl)
@@ -13,8 +13,8 @@ x | typealias Ref<T> = ref.Reference<D, T>
^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^
at reference11#Ref (file:///$snippetsDir/input/errors/reference11.pkl) at reference11#Ref (file:///$snippetsDir/input/errors/reference11.pkl)
x | test = ref.Reference(d, String, "") as Ref<Alias1?> x | test = ref.Reference(d, String, "") as Ref<Alias1>
^^^^^^^^^^^^ ^^^^^^^^^^^
at reference11#test (file:///$snippetsDir/input/errors/reference11.pkl) at reference11#test (file:///$snippetsDir/input/errors/reference11.pkl)
xxx | renderer.renderDocument(value) xxx | renderer.renderDocument(value)
@@ -5,6 +5,8 @@ x | test = ref.Reference(d, Mapping, "").default
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
at reference13#test (file:///$snippetsDir/input/errors/reference13.pkl) at reference13#test (file:///$snippetsDir/input/errors/reference13.pkl)
Cannot reference property `default` in class `Mapping`.
xxx | renderer.renderDocument(value) xxx | renderer.renderDocument(value)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
at pkl.base#Module.output.text (pkl:base) at pkl.base#Module.output.text (pkl:base)
@@ -5,6 +5,8 @@ x | test = ref.Reference(d, Listing, "").default
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
at reference14#test (file:///$snippetsDir/input/errors/reference14.pkl) at reference14#test (file:///$snippetsDir/input/errors/reference14.pkl)
Cannot reference property `default` in class `Listing`.
xxx | renderer.renderDocument(value) xxx | renderer.renderDocument(value)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
at pkl.base#Module.output.text (pkl:base) at pkl.base#Module.output.text (pkl:base)
@@ -5,6 +5,8 @@ x | test = ref.Reference(d, Dynamic, "").default
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
at reference15#test (file:///$snippetsDir/input/errors/reference15.pkl) at reference15#test (file:///$snippetsDir/input/errors/reference15.pkl)
Cannot reference property `default` in class `Dynamic`.
xxx | renderer.renderDocument(value) xxx | renderer.renderDocument(value)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
at pkl.base#Module.output.text (pkl:base) at pkl.base#Module.output.text (pkl:base)
@@ -5,6 +5,8 @@ xx | test = ref.Reference(d, ReferencedModule.getClass(), "").output
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
at reference16#test (file:///$snippetsDir/input/errors/reference16.pkl) at reference16#test (file:///$snippetsDir/input/errors/reference16.pkl)
Cannot reference property `output` because it is defined inside external class `Module`.
xxx | renderer.renderDocument(value) xxx | renderer.renderDocument(value)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
at pkl.base#Module.output.text (pkl:base) at pkl.base#Module.output.text (pkl:base)
@@ -5,6 +5,8 @@ xx | test = ref.Reference(d, ReferencedModuleWithOutputOverride.getClass(), "").
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
at reference17#test (file:///$snippetsDir/input/errors/reference17.pkl) at reference17#test (file:///$snippetsDir/input/errors/reference17.pkl)
Cannot reference property `output` because it is defined inside external class `Module`.
xxx | renderer.renderDocument(value) xxx | renderer.renderDocument(value)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
at pkl.base#Module.output.text (pkl:base) at pkl.base#Module.output.text (pkl:base)
@@ -5,6 +5,8 @@ xx | test = ref.Reference(d, ModuleSubclass, "").output
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
at reference18#test (file:///$snippetsDir/input/errors/reference18.pkl) at reference18#test (file:///$snippetsDir/input/errors/reference18.pkl)
Cannot reference property `output` because it is defined inside external class `Module`.
xxx | renderer.renderDocument(value) xxx | renderer.renderDocument(value)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
at pkl.base#Module.output.text (pkl:base) at pkl.base#Module.output.text (pkl:base)
@@ -0,0 +1,17 @@
–– Pkl Error ––
Cannot find property `name` in object of type `pkl.ref#Reference<reference24#D, Int | reference24#Bird>`.
xx | res = myRef.name
^^^^^^^^^^
at reference24#res (file:///$snippetsDir/input/errors/reference24.pkl)
Cannot find property `name` in type `Int | reference24#Bird`.
└─ Cannot find property `name` in type `Int`.
xxx | renderer.renderDocument(value)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
at pkl.base#Module.output.text (pkl:base)
xxx | if (renderer is BytesRenderer) renderer.renderDocument(value) else text.encodeToBytes("UTF-8")
^^^^
at pkl.base#Module.output.bytes (pkl:base)
@@ -0,0 +1,19 @@
–– Pkl Error ––
Operator `[]` is not defined for operand types `pkl.ref#Reference<reference25#D, Duration | Listing<String>>` and `Int`.
Left operand : Reference(new D {}, Duration | Listing<String>, null).$
Right operand: 0
xx | res = myRef[0]
^^^^^^^^
at reference25#res (file:///$snippetsDir/input/errors/reference25.pkl)
Operator `[]` is not defined for operand types `Duration | Listing<String>` and `Int`.
└─ Operator `[]` is not defined for operand types `Duration` and `Int`.
xxx | renderer.renderDocument(value)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
at pkl.base#Module.output.text (pkl:base)
xxx | if (renderer is BytesRenderer) renderer.renderDocument(value) else text.encodeToBytes("UTF-8")
^^^^
at pkl.base#Module.output.bytes (pkl:base)
@@ -0,0 +1,16 @@
–– Pkl Error ––
Cannot find property `name` in object of type `pkl.ref#Reference<reference26#D, Listing<unknown>>`.
x | res = myRef.name
^^^^^^^^^^
at reference26#res (file:///$snippetsDir/input/errors/reference26.pkl)
Cannot find property `name` in type `Listing<unknown>`.
xxx | renderer.renderDocument(value)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
at pkl.base#Module.output.text (pkl:base)
xxx | if (renderer is BytesRenderer) renderer.renderDocument(value) else text.encodeToBytes("UTF-8")
^^^^
at pkl.base#Module.output.bytes (pkl:base)
@@ -0,0 +1,16 @@
–– Pkl Error ––
Cannot find property `name` in object of type `pkl.ref#Reference<reference27#D, (Int) -> Boolean>`.
xx | res = myRef.name
^^^^^^^^^^
at reference27#res (file:///$snippetsDir/input/errors/reference27.pkl)
Cannot find property `name` in type `(Int) -> Boolean`.
xxx | renderer.renderDocument(value)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
at pkl.base#Module.output.text (pkl:base)
xxx | if (renderer is BytesRenderer) renderer.renderDocument(value) else text.encodeToBytes("UTF-8")
^^^^
at pkl.base#Module.output.bytes (pkl:base)
@@ -1,5 +1,5 @@
–– Pkl Error –– –– Pkl Error ––
Expected value of type `pkl.ref#Reference<reference4#D, reference4#Alias1?>`, but got type `pkl.ref#Reference<reference4#D, String>`. Expected value of type `pkl.ref#Reference<reference4#D, reference4#Alias1>`, but got type `pkl.ref#Reference<reference4#D, String>`.
Value: Reference(new D {}, String, "") Value: Reference(new D {}, String, "")
x | typealias Ref<T> = ref.Reference<D, T> x | typealias Ref<T> = ref.Reference<D, T>
@@ -5,6 +5,8 @@ xx | test = ref.Reference(d, String, new A {}).c
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
at reference6#test (file:///$snippetsDir/input/errors/reference6.pkl) at reference6#test (file:///$snippetsDir/input/errors/reference6.pkl)
Cannot find property `c` in type `String`.
xxx | renderer.renderDocument(value) xxx | renderer.renderDocument(value)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
at pkl.base#Module.output.text (pkl:base) at pkl.base#Module.output.text (pkl:base)
@@ -7,6 +7,8 @@ x | test = ref.Reference(d, List, List())["hi"]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
at reference7#test (file:///$snippetsDir/input/errors/reference7.pkl) at reference7#test (file:///$snippetsDir/input/errors/reference7.pkl)
Operator `[]` is not defined for operand types `List<unknown>` and `String`.
xxx | renderer.renderDocument(value) xxx | renderer.renderDocument(value)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
at pkl.base#Module.output.text (pkl:base) at pkl.base#Module.output.text (pkl:base)