mirror of
https://github.com/apple/pkl.git
synced 2026-05-21 22:36:57 +02:00
Fix name resolution in typealias with constraint (#144)
The body of a typealias gets inlined into wherever the typealias is used. This fixes a bug where the references in the typealias body can resolve to the wrong value.
This commit is contained in:
+3
@@ -0,0 +1,3 @@
|
||||
class MyClass
|
||||
|
||||
typealias MyTypeAlias = MyClass(getClass() == MyClass)
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// length should bind to `String#length` instead of `ClassWithLengthProperty#length`
|
||||
local typealias OneCharacterString = String(length == 1)
|
||||
|
||||
local class ClassWithLengthProperty {
|
||||
length: Int = 99
|
||||
|
||||
// length constraint binds to ClassWithLengthProperty.length here
|
||||
characters: List<OneCharacterString> = List("a", "b")
|
||||
}
|
||||
|
||||
res1: OneCharacterString = "a"
|
||||
res2 = let (c = new ClassWithLengthProperty {}) c.characters
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
import ".../input-helper/types/typeAliasConstraint2.pkl" as helper
|
||||
|
||||
foo: Int = 1
|
||||
bar: helper.MyTypeAlias(foo == 1) = new helper.MyClass {}
|
||||
|
||||
function qux(bar: helper.MyTypeAlias(foo == 1)) = (bar) {}
|
||||
|
||||
qux = qux(new helper.MyTypeAlias {})
|
||||
@@ -341,8 +341,8 @@ examples {
|
||||
"abcdefg"
|
||||
"abcdefg"
|
||||
" abcdefg"
|
||||
"Type constraint `this.length == 1` violated. Value: \"\""
|
||||
"Type constraint `this.length == 1` violated. Value: \"aa\""
|
||||
"Type constraint `length == 1` violated. Value: \"\""
|
||||
"Type constraint `length == 1` violated. Value: \"aa\""
|
||||
}
|
||||
["padEnd()"] {
|
||||
""
|
||||
@@ -351,8 +351,8 @@ examples {
|
||||
"abcdefg"
|
||||
"abcdefg"
|
||||
"abcdefg "
|
||||
"Type constraint `this.length == 1` violated. Value: \"\""
|
||||
"Type constraint `this.length == 1` violated. Value: \"aa\""
|
||||
"Type constraint `length == 1` violated. Value: \"\""
|
||||
"Type constraint `length == 1` violated. Value: \"aa\""
|
||||
}
|
||||
["toBooleanOrNull()"] {
|
||||
true
|
||||
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
res1 = "a"
|
||||
res2 = List("a", "b")
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
foo = 1
|
||||
bar {}
|
||||
qux {}
|
||||
Reference in New Issue
Block a user