pkl icon indicating copy to clipboard operation
pkl copied to clipboard

Type checking a mapping/listing should be lazy

Open bioball opened this issue 1 year ago • 2 comments

Currently, accessing a property of type Mapping<TypeA, TypeB> or Listing<Type> will shallow-force the whole mapping/listing. The shallow-force gets skipped if the type is unknown or Any (e.g. Listing, or Listing<unknown>, or Listing<Any>).

This should not throw, but does currently:

hidden nums: Listing<Int> = new {
  throw("uh oh")
  1
}

result = nums[1]

This is related to #405

bioball avatar Apr 05 '24 23:04 bioball

This is just another example. The addition happens and we get 33 but at what point is the type checking meant to happen. Using the IntelliJ plugin I get warnings telling me I'm doing something stupid.

foo = new Listing<YamlRenderer> {
  11
}

bar = new Listing<String> {
  22
}

output {
  value = foo[0] + bar[0]
  renderer = new YamlRenderer{}
}

output

33

harryjackson avatar Apr 06 '24 08:04 harryjackson

@harryjackson: what you're seeing is the #405 bug, rather than this one. To fix, you should add a type annotation to your properties:

foo: Listing<YamlRenderer> = new {
  11
}

bar: Listing<String> = new {
  22
}

output {
  value = foo[0] + bar[0]
  renderer = new YamlRenderer{}
}

bioball avatar Apr 07 '24 16:04 bioball