Skip to content

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

Open
@HT154

Description

@HT154

Noticed this while testing out apple/pkl-pantry#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...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions