mirror of
https://github.com/apple/pkl.git
synced 2026-01-11 22:30:54 +01:00
Type constraints on typealiases are evaluated eagerly
#150
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @sin-ack on GitHub (Apr 22, 2024).
Consider the following (the required
typealiasredirection is another issue):As expected. However, if we change
foo's definition to:Then I get:
Placing a
trace()onbarreveals thatbaris aMapping {}during the evaluation of the constraint, which is unexpected (to me at least). Is this intended behavior?@odenix commented on GitHub (Apr 22, 2024):
My understanding is that accessing
barfrom within a type constraint isn’t allowed because it isn’tconst. If you don’t get an error for that it’s probably a bug.@holzensp commented on GitHub (Apr 23, 2024):
I can't reproduce this (but also; the snippets you included are not syntactically valid Pkl, so I think something got lost in reduction of the example).
There is a known bug that
typealiases resolved names in their definition scope, instead of their use scope. This has been addressed in #373 and will be part of 0.26 (hopefully June).By the way,
toMap()already forces the entireMapping(keys and values). If you want to keep things lazy, considerkeys.intersect(bar.keys) == keysinstead.@bioball commented on GitHub (Apr 25, 2024):
I think @sin-ack is using 0.26.0-dev, which reproduces for me.
We currently have an issue in the latest dev version where typealias bodies are not late-bound (changed a fix for a scoping bug in https://github.com/apple/pkl/pull/144). But, at the same time, they aren't required to be
const.We're thinking through whether typealias bodies should be late-bound, or if this is actually the correct behavior. If this is the correct behavior, then we will add an additional rule that references must be const. If not, then we need to adjust the behavior here so that those references are late-bound.