apple / apple/pkl

Incorrect inferred parent in `new {}` expression

Open
#1,576 0 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

This snippet throws:

```pkl
class Foo {
bar: Listing(!isEmpty)

foo: Listing = bar
}

foo: Foo = new {
bar = new Listing { 1; 2; 3 }
foo = new {
qux
}
}
```

Produces error:

```
–– Pkl Error ––
Type constraint `!isEmpty` violated.
Value: new Listing {}

!isEmpty
││
│true
false

2 | bar: Listing(!isEmpty)
^^^^^^^^
at test#Foo.bar (/Users/danielchao/code/apple/pkl/.dan-scripts/test.pkl:2)

2 | bar: Listing(!isEmpty)
^^^
at test#Foo.bar (/Users/danielchao/code/apple/pkl/.dan-scripts/test.pkl:2)

3 | foo: Listing = bar
^^^
at test#Foo.foo (/Users/danielchao/code/apple/pkl/.dan-scripts/test.pkl:3)

132 | renderer.renderDocument(value)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
at pkl.base#Module.output.text (https://github.com/apple/pkl/blob/0.31.0/stdlib/base.pkl#L132)

136 | if (renderer is BytesRenderer) renderer.renderDocument(value) else text.encodeToBytes("UTF-8")
^^^^
at pkl.base#Module.output.bytes (https://github.com/apple/pkl/blob/0.31.0/stdlib/base.pkl#L136)
```

Contributor guide

Open the contributing guide

Research direction

Start by running the provided Pkl snippet and compare the inferred parent for the nested `new {}` expression with the reported empty `Listing` value. Trace the compiler or evaluator path that resolves the parent of `foo` and verify that the `bar: Listing(!isEmpty)` constraint is satisfied without producing the shown error.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.