apple / apple/pkl

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

Open
#1,027 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
11.5k
Forks
402
Avg merge
1d 15h
Merged PRs (30d)
20

Description

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...
```

Contributor guide

Open the contributing guide

Research direction

Start with the Recur module and the type-constraint error path using the reproduction in the issue. Compare the current diagnostic with the canonical formatting described in pkl-evolution/pull/15; done means inline comments and source formatting no longer appear in the reported constraint type.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.