toTyped ignores default values in class #238

Open
opened 2025-12-30 01:22:36 +01:00 by adam · 0 comments
Owner

Originally created by @holzensp on GitHub (Nov 1, 2024).

Given

class Bird {
  name: String = "DEFAULT"
  colloquialName: String = name
}

evaluating

new Dynamic { name = "Pigeon" }.toTyped(Bird)

results in

new Bird {
  name = "Pigeon"
  colloquialName = "DEFAULT" // <- unexpected
}

The same holds for the toTyped definition on Map, so the following produces the same result:

new Dynamic { name = "Pigeon" }.toMap().toTyped(Bird)
Originally created by @holzensp on GitHub (Nov 1, 2024). Given ``` class Bird { name: String = "DEFAULT" colloquialName: String = name } ``` evaluating ``` new Dynamic { name = "Pigeon" }.toTyped(Bird) ``` results in ``` new Bird { name = "Pigeon" colloquialName = "DEFAULT" // <- unexpected } ``` The same holds for the `toTyped` definition on `Map`, so the following produces the same result: ``` new Dynamic { name = "Pigeon" }.toMap().toTyped(Bird) ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/pkl#238