Typecheck Mapping/Listing members lazily (#628)

This changes how the language performs typechecks for mappings and
listings.

Currently, Pkl will shallow-force any Mapping and Listing to check it
the type parameter (e.g. Listing<Person> means each element is checked
to be an instance of Person).

This changes the language to check each member's type when the member
is accessed.

This also adjust test runner to handle thrown errors from within tests.

With the change to make mapping/listing typechecks lazy, we can now
correctly handle thrown errors from within a single test case.

This adjusts the test runner to consider any thrown errors as a failure
for that specific test case.
This commit is contained in:
Daniel Chao
2024-09-06 15:05:23 -07:00
committed by GitHub
parent 7001a42149
commit 7868d9d9c8
86 changed files with 3342 additions and 385 deletions

View File

@@ -71,10 +71,12 @@ class TestsTest : AbstractTest() {
val output = runTask("evalTest", expectFailure = true).output.stripFilesAndLines()
assertThat(output)
.contains(
.containsIgnoringNewLines(
"""
> Task :evalTest FAILED
module test (file:///file, line x)
test ❌
should pass ✅
error ❌
Error:
Pkl Error
exception
@@ -82,11 +84,7 @@ class TestsTest : AbstractTest() {
9 | throw("exception")
^^^^^^^^^^^^^^^^^^
at test#facts["error"][#1] (file:///file, line x)
3 | facts {
^^^^^^^
at test#facts (file:///file, line x)
"""
"""
.trimIndent()
)
}
@@ -122,7 +120,6 @@ class TestsTest : AbstractTest() {
name = "Pigeon"
age = 41
}
user 1 ❌
(file:///file, line x)
Expected: (file:///file, line x)
new {
@@ -189,7 +186,7 @@ class TestsTest : AbstractTest() {
.isEqualTo(
"""
<?xml version="1.0" encoding="UTF-8"?>
<testsuite name="test" tests="6" failures="4">
<testsuite name="test" tests="5" failures="4">
<testcase classname="test" name="sum numbers"></testcase>
<testcase classname="test" name="divide numbers"></testcase>
<testcase classname="test" name="fail">
@@ -209,8 +206,6 @@ class TestsTest : AbstractTest() {
name = &quot;Pigeon&quot;
age = 41
}</failure>
</testcase>
<testcase classname="test" name="user 1">
<failure message="Example Failure">(file:///file, line x)
Expected: (file:///file, line x)
new {
@@ -226,7 +221,7 @@ class TestsTest : AbstractTest() {
<system-err><![CDATA[8 = 8
]]></system-err>
</testsuite>
"""
.trimIndent()
)