Fix replacements of types nested within nested constraints (#1731)

Also, adjust tests
This commit is contained in:
Daniel Chao
2026-07-06 08:58:56 -07:00
committed by GitHub
parent 26c115aea6
commit 2ec83198f5
5 changed files with 32 additions and 34 deletions
@@ -1,3 +1,17 @@
typealias MyList<T> = List(this[0] is T)
import "pkl:test"
foo: MyList<Int> = List("uh oh")
typealias MyList<T> = List(this[0] is T)
typealias MyList2<T> = List((this[0] as T) != null)
typealias MyList3<T> = List((this[0] is Any(this is T)))
typealias MyList4<T> = List((this[0] is T(!(this is T))))
typealias MyList5<T> = List((this[0] is T(true)))
typealias MyList6<T> = List(this[0] is T?)
local foo = List("uh oh")
res = test.catch(() -> foo as MyList<Int>)
res2 = test.catch(() -> foo as MyList2<Int>)
res3 = test.catch(() -> foo as MyList3<Int>)
res4 = test.catch(() -> foo as MyList4<String>)
res5 = test.catch(() -> foo as MyList5<Int>)
res6 = test.catch(() -> foo as MyList6<Int>)
@@ -1,25 +0,0 @@
–– Pkl Error ––
Type constraint `this[0] is T` violated.
Value: List("uh oh")
this[0] is T
│ │ │
│ │ false
│ "uh oh"
List("uh oh")
x | typealias MyList<T> = List(this[0] is T)
^^^^^^^^^^^^
at typeAliasConstraint3#foo (file:///$snippetsDir/input/types/typeAliasConstraint3.pkl)
x | foo: MyList<Int> = List("uh oh")
^^^^^^^^^^^^^
at typeAliasConstraint3#foo (file:///$snippetsDir/input/types/typeAliasConstraint3.pkl)
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,6 @@
res = "Type constraint `this[0] is T` violated. Value: List(\"uh oh\")"
res2 = "Expected value of type `Int`, but got type `String`. Value: \"uh oh\""
res3 = "Type constraint `this[0] is Any(this is T)` violated. Value: \"u\""
res4 = "Type constraint `this[0] is T(!(this is T))` violated. Value: \"u\""
res5 = "Type constraint `this[0] is T(true)` violated. Value: List(\"uh oh\")"
res6 = "Type constraint `this[0] is T?` violated. Value: List(\"uh oh\")"