Skip to content

Incorrect inferred parent in new {} expression #1576

Description

@bioball

This snippet throws:

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions