apple / apple/pkl

Type constraints on `typealias`es are evaluated eagerly

Open
#446 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
11.5k
Forks
402
Avg merge
1d 15h
Merged PRs (30d)
20

Description

Consider the following (the required `typealias` redirection is another issue):

```pkl
// foo.pkl
typealias FooMapping = Mapping
foo: FooMapping(toMap().every((k, v) -> bar.containsKey(k))

bar: Mapping

// bar.pkl
amends "./foo.pkl"

bar {
"a" = true
"b" = false
}

foo {
"a" = "aaa"
}
```

```console
$ pkl eval bar.pkl
foo {
["a"] = "aaa"
}
bar {
["a"] = true
["b"] = false
}
```

As expected. However, if we change `foo`'s definition to:

```pkl
typealias FooMapping1 = Mapping
typealias FooMapping = FooMapping1(toMap().every((k, v) -> bar.containsKey(k))
foo: FooMapping
```

Then I get:

```console
$ pkl eval bar.pkl
–– Pkl Error ––
Type constraint `toMap().every((k, v) -> bar.containsKey(k))` violated.
Value: new Mapping { ["a"] = "aaa" }

2 | typealias FooMapping = FooMapping1(toMap().every((k, v) -> bar.containsKey(k)))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
at foo#foo (file:///.../foo.pkl, line 2)

8 | foo {
^^^^^
at bar#foo (file:///.../bar.pkl, line 8)
```

Placing a `trace()` on `bar` reveals that `bar` is a `Mapping {}` during the evaluation of the constraint, which is unexpected (to me at least). Is this intended behavior?

Contributor guide

Open the contributing guide

Research direction

Reproduce the behavior with the issue's foo.pkl and bar.pkl examples by running `pkl eval bar.pkl`. Trace the evaluation of the typealias constraint and compare the direct and redirected aliases; done means the intended evaluation timing is established and covered by an appropriate regression test.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.