Add inference for implicitly typed new in method arguments (#1768)

This commit is contained in:
Jen Basch
2026-09-02 23:55:24 +00:00
committed by GitHub
parent 92b26aca17
commit 7f5ae2a712
34 changed files with 678 additions and 323 deletions
@@ -0,0 +1,50 @@
open module inferParameterType
import "pkl:test"
hidden x: Int
open class Foo extends module {
function bar(baz: Foo): Int = super.bar(baz) * this.x
function superBar(baz: Foo): Int = super.bar(new { x = 5 + baz.x }) * this.x
function thisBar(baz: Foo): Int = this.x + baz.x
}
class Qux extends Foo {
function bar(baz: Foo): Int = thisBar(new { x = baz.x })
}
function bar(baz: Foo): Int = baz.x
const function outerMethod(a: Int, b: Qux) = a + b.x * 2
local quux = (a: Foo) -> a.x
qualified = this.bar(new { x = 1 })
unqualifiedLexical = bar(new { x = 1 })
unqualifiedThis = new Qux { x = 7 }.bar(new { x = 1 })
`super` = new Foo { x = 2 }.superBar(new Foo { x = 3 })
nestedMethodCalls = outerMethod(bar(new { x = 8 }), new { x = 9 })
objectMethod {
local function corge(prop: Foo) = prop
call = corge(new { x = 0 }).x
tooManyParams = test.catch(() -> corge(new {}, new {}))
}
intrinsicConstructor = test.catch(() -> List(new {}))
genericMethod = test.catch(() -> Pair(new {}, new {}))
fnApply = test.catch(() -> quux.apply(new {}))
tooManyParams = test.catch(() -> bar(new {}, new {}))
class Bar1 { x: Int = 1 }
class Bar2 { x: Int = 2 }
class C1 { function f(p: Bar1) = p.x }
class C2 { function f(p: Bar2) = p.x * 10 }
local function call(a) = a.f(new {}) // poly call
polyCall1 = call(new C1 {})
polyCall2 = call(new C2 {})
@@ -139,18 +139,18 @@ one {
res31 {
name = "Other"
}
res32 = "Expected 1 function arguments but got 2."
res32 = "Expected 1 function argument but got 2."
res33 {
name = "Override"
}
res34 = "Expected 1 function arguments but got 2."
res34 = "Expected 1 function argument but got 2."
res35 {
name = "Other"
}
res36 = "Expected 1 function arguments but got 2."
res36 = "Expected 1 function argument but got 2."
res37 = "Expected value of type `new#Person`, but got type `Int`. Value: 1"
res38 {
name = "Override"
}
res39 = "Expected 1 function arguments but got 2."
res39 = "Expected 1 function argument but got 2."
res40 = "Expected value of type `new#Person`, but got type `Int`. Value: 1"
@@ -63,20 +63,20 @@ res8 {
res9 {
name = "Other"
}
res9b = "Expected 1 function arguments but got 2."
res9b = "Expected 1 function argument but got 2."
res9c {
name = "Override"
}
res9d = "Expected 1 function arguments but got 2."
res9d = "Expected 1 function argument but got 2."
res10 {
name = "Other"
}
res10b = "Expected 1 function arguments but got 2."
res10b = "Expected 1 function argument but got 2."
res10c = "Expected value of type `newType#Person`, but got type `Int`. Value: 1"
res10d {
name = "Override"
}
res10e = "Expected 1 function arguments but got 2."
res10e = "Expected 1 function argument but got 2."
res10f = "Expected value of type `newType#Person`, but got type `Int`. Value: 1"
res11 {
name = "Pigeon"
@@ -0,0 +1,15 @@
qualified = 1
unqualifiedLexical = 1
unqualifiedThis = 8
`super` = 16
nestedMethodCalls = 26
objectMethod {
call = 0
tooManyParams = "Expected 1 function argument but got 2."
}
intrinsicConstructor = "Cannot tell which parent to amend."
genericMethod = "Cannot tell which parent to amend."
fnApply = "Cannot tell which parent to amend."
tooManyParams = "Expected 1 function argument but got 2."
polyCall1 = 1
polyCall2 = 20