Poor typecheck error message when using absolute package import for project dependency
- Dominant language
- Java
- Stars
- 11.5k
- Forks
- 402
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 20
Description
[bioball] When using an absolute package import in place of a project import, Pkl eval will fail (expected). However, the error message thrown by Pkl is quite poor.
Original issue:
---
## Given
`PklProject`:
```pkl
amends "pkl:Project"
dependencies {
["pkl.impl.ghactions"] { uri = "package://pkg.pkl-lang.org/pkl-project-commons/pkl.impl.ghactions@0.4.2" }
["gha"] { uri = "package://pkg.pkl-lang.org/github.com/stefma/pkl-gha/com.github.action@0.0.6" }
}
```
`index.pkl`:
```pkl
amends "@gha/Workflow.pkl"
import "ver/test.pkl"
name = "PKL IntelliJ CI"
on {
public {}
}
jobs {
["a"] {
name = "Placeholder"
`runs-on` = "ubuntu-latest"
steps {
new {
name = "Do nothing"
run = "echo 'This is a placeholder job.'"
}
new test.Action {
with {
`java-version` = ""
}
}
}
}
}
```
`ver/test.pkl`:
```pkl
import "package://pkg.pkl-lang.org/github.com/stefma/pkl-gha/com.github.action@0.0.6#/Workflow.pkl"
class Action extends Workflow.TypedStep {
fixed uses = "actions/setup-java@v3"
with: ActionInputs?
}
class ActionInputs {
`java-version`: (String|Number|Boolean)?
}
```
> [!CAUTION]
> Note the different imports. `ver/test.pkl` doesn't use `@gha` but the full package import.
## When-Then
If I run `pkl eval index.pkl` then I get the following error
```
–– Pkl Error ––
Expected value of type `*Step|TypedStep`, but got type `test#Action`.
Value: new Action { name = ?; id = ?; `if` = ?; `timeout-minutes` = ?; env = ?; `wor...
1019 | steps: Listing<*Step|TypedStep>
^^^^^^^^^^^^^^^
at com.github.action.Workflow#DefaultJob.steps (projectpackage://pkg.pkl-lang.org/github.com/stefma/pkl-gha/com.github.action@0.0.6#/Workflow.pkl)
21 | new test.Action {
^^^^^^^^^^^^^^^^^
at index#jobs["a"].steps[#2] (file:///Users/stefan/Developer/pkl/pkl-intellij/.github/index.pkl, line 21)
128 | renderer.renderDocument(value)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
at pkl.base#Module.output.text (https://github.com/apple/pkl/blob/0.30.0/stdlib/base.pkl#L128)
1318 | text = "# Do not modify!\n# This file was generated from a template using https://github.com/StefMa/pkl-gha\n\n\(super.text)"
^^^^^^^^^^
at com.github.action.Workflow#output.text (projectpackage://pkg.pkl-lang.org/github.com/stefma/pkl-gha/com.github.action@0.0.6#/Workflow.pkl)
132 | if (renderer is BytesRenderer) renderer.renderDocument(value) else text.encodeToBytes("UTF-8")
^^^^
at pkl.base#Module.output.bytes (https://github.com/apple/pkl/blob/0.30.0/stdlib/base.pkl#L132)
```
## Possible solution
Use the same import statement in both files!
Either use `@gha/` or `package://` in index.pkl **and** `ver/test.pkl`
## Observation
Even though the import **is the same**, `pkl` doesn't know that it is "valid".
One pkl file uses the dependency notion (defined in `PklProject`), while the other uses the package import.
## Expectation
I would expect that `pkl` can detect that using the `@gha` import is equal to the `package://` import (for the same package obviously) and therefore don't error in such a import mix case.
---
Feel free to change the title of this issue.
I've no idea how to call this 🫣
Contributor guide
Research direction
Reproduce the issue with PklProject, index.pkl, and ver/test.pkl by running `pkl eval index.pkl`, then inspect the reported type mismatch and import forms. Done means equivalent `@gha/` and `package://` imports are recognized consistently, with an improved error outcome for this case.
Written by the indexing model from the issue text.
Assessment
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100