Type constraint violation error messages include formatting/comments from original definition #302

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

Originally created by @HT154 on GitHub (Mar 21, 2025).

Noticed this while testing out https://github.com/apple/pkl-pantry/pull/105

The Recur module includes some fairly complex type constraints with comments inline for clarity, eg.

until: (
  * DateTime(
      // if dtstart is defined and a datetime, until must also be a datetime if defined
      dtstart?.ifNonNull((it) -> it is DateTime) ?? true,
      dtstart?.ifNonNull((it) -> utc == (it as DateTime).utc) ?? true,
      utc.implies(tzid == null)
    )
  |Date(
    // if dtstart is defined and a date, until must also be a date if defined
    dtstart?.ifNonNull((it) -> it is Date) ?? true,
    tzid == null
  )
  )?

If non of these constraints can be satisfied, eg. by input such as

import "@icalendar/Recur.pkl"
result = new Recur {
  tzid = "America/Los_Angeles"
  freq = "YEARLY"
  until = DateTime.DateTime("20250101T000000Z")
}.toString()

Then the resulting error message will include the full original code with only newlines stripped:

Expected value of type `* DateTime(       // if dtstart is defined and a datetime, until must also be a datetime if defined       dtstart?.ifNonNull((it) -> it is DateTime) ?? true,       dtstart?.ifNonNull((it) -> utc == (it as DateTime).utc) ?? true,       utc.implies(tzid == null)     )   |Date(     // if dtstart is defined and a date, until must also be a date if defined     dtstart?.ifNonNull((it) -> it is Date) ?? true,     tzid == null   )`, but got a different `icalendar.DateTime`. Value: new ModuleClass { date = ?; time { h = ?; m = ?; s = ?; utc = true }; utc = t...

Ideally this should produce output with the type/constraints canonically formatted, eg. (without addition of newlines for line length)

Expected value of type `*DateTime(dtstart?.ifNonNull((it) -> it is DateTime) ?? true, dtstart?.ifNonNull((it) -> utc == (it as DateTime).utc) ?? true, utc.implies(tzid == null))|Date(dtstart?.ifNonNull((it) -> it is Date) ?? true, tzid == null)`, but got a different `icalendar.DateTime`. Value: new ModuleClass { date = ?; time { h = ?; m = ?; s = ?; utc = true }; utc = t...
Originally created by @HT154 on GitHub (Mar 21, 2025). Noticed this while testing out https://github.com/apple/pkl-pantry/pull/105 The `Recur` module includes some fairly complex type constraints with comments inline for clarity, eg. ```pkl until: ( * DateTime( // if dtstart is defined and a datetime, until must also be a datetime if defined dtstart?.ifNonNull((it) -> it is DateTime) ?? true, dtstart?.ifNonNull((it) -> utc == (it as DateTime).utc) ?? true, utc.implies(tzid == null) ) |Date( // if dtstart is defined and a date, until must also be a date if defined dtstart?.ifNonNull((it) -> it is Date) ?? true, tzid == null ) )? ``` If non of these constraints can be satisfied, eg. by input such as ```pkl import "@icalendar/Recur.pkl" result = new Recur { tzid = "America/Los_Angeles" freq = "YEARLY" until = DateTime.DateTime("20250101T000000Z") }.toString() ``` Then the resulting error message will include the full original code with only newlines stripped: ``` Expected value of type `* DateTime( // if dtstart is defined and a datetime, until must also be a datetime if defined dtstart?.ifNonNull((it) -> it is DateTime) ?? true, dtstart?.ifNonNull((it) -> utc == (it as DateTime).utc) ?? true, utc.implies(tzid == null) ) |Date( // if dtstart is defined and a date, until must also be a date if defined dtstart?.ifNonNull((it) -> it is Date) ?? true, tzid == null )`, but got a different `icalendar.DateTime`. Value: new ModuleClass { date = ?; time { h = ?; m = ?; s = ?; utc = true }; utc = t... ``` Ideally this should produce output with the type/constraints [canonically formatted](https://github.com/apple/pkl-evolution/pull/15), eg. (without addition of newlines for line length) ``` Expected value of type `*DateTime(dtstart?.ifNonNull((it) -> it is DateTime) ?? true, dtstart?.ifNonNull((it) -> utc == (it as DateTime).utc) ?? true, utc.implies(tzid == null))|Date(dtstart?.ifNonNull((it) -> it is Date) ?? true, tzid == null)`, but got a different `icalendar.DateTime`. Value: new ModuleClass { date = ?; time { h = ?; m = ?; s = ?; utc = true }; utc = t... ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/pkl#302