Originally created by @othompson2 on GitHub (Mar 10, 2024).
I am trying to define and type a variable using the module self type, however when I attempt to use it I encounter an error. The error suggests it is trying to match to the module type so the self type is working, however its not able to implicitly map the Dynamic type to it, this can be resolved by explicitly typing it.
I feel like the expected behaviour would be that they do the same thing, however it appears the module keyword currently only supports importing another file rather than defining the sub-module in place. In most circumstances would be fine to switch to the other syntax, but I am trying to define the example variable in a module and then extend it before amending it - so I need to self-type for it to work.
Error
// Bird.pkl
example: module?
test: Boolean?
When I try to use variable example in a module which amends Bird.pkl
// example.pkl
amends "Bird.pkl"
example {
test = true
}
I get the following error:
–– Pkl Error ––
Expected value of type `Bird`, but got type `Dynamic`.
Value: new Dynamic { test = ? }
2 | example: module?
^^^^^^
at Bird#example (file:///Bird.pkl, line 2)
4 | example {
^^^^^^^^^
at example#example (file:///example.pkl, line 4)
106 | text = renderer.renderDocument(value)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
at pkl.base#Module.output.text (https://github.com/apple/pkl/blob/0.25.2/stdlib/base.pkl#L106)
However if I update the example variable with an explicit self reference the error goes away and it functions as expected.
example {
example = null
test = true
}
test = null
Originally created by @othompson2 on GitHub (Mar 10, 2024).
I am trying to define and type a variable using the `module` self type, however when I attempt to use it I encounter an error. The error suggests it is trying to match to the module type so the self type is working, however its not able to implicitly map the `Dynamic` type to it, this can be resolved by explicitly typing it.
I feel like the expected behaviour would be that they do the same thing, however it appears the `module` keyword currently only supports importing another file rather than defining the sub-module in place. In most circumstances would be fine to switch to the other syntax, but I am trying to define the `example` variable in a module and then extend it before amending it - so I need to self-type for it to work.
---
### Error
```
// Bird.pkl
example: module?
test: Boolean?
```
When I try to use variable `example` in a module which amends `Bird.pkl`
```
// example.pkl
amends "Bird.pkl"
example {
test = true
}
```
I get the following error:
```
–– Pkl Error ––
Expected value of type `Bird`, but got type `Dynamic`.
Value: new Dynamic { test = ? }
2 | example: module?
^^^^^^
at Bird#example (file:///Bird.pkl, line 2)
4 | example {
^^^^^^^^^
at example#example (file:///example.pkl, line 4)
106 | text = renderer.renderDocument(value)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
at pkl.base#Module.output.text (https://github.com/apple/pkl/blob/0.25.2/stdlib/base.pkl#L106)
```
---
However if I update the `example` variable with an explicit self reference the error goes away and it functions as expected.
```
// Bird.pkl
import "Bird.pkl"
example: Bird?
test: Boolean?
```
outputs:
```
example {
example = null
test = true
}
test = null
```
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Originally created by @othompson2 on GitHub (Mar 10, 2024).
I am trying to define and type a variable using the
moduleself type, however when I attempt to use it I encounter an error. The error suggests it is trying to match to the module type so the self type is working, however its not able to implicitly map theDynamictype to it, this can be resolved by explicitly typing it.I feel like the expected behaviour would be that they do the same thing, however it appears the
modulekeyword currently only supports importing another file rather than defining the sub-module in place. In most circumstances would be fine to switch to the other syntax, but I am trying to define theexamplevariable in a module and then extend it before amending it - so I need to self-type for it to work.Error
When I try to use variable
examplein a module which amendsBird.pklI get the following error:
However if I update the
examplevariable with an explicit self reference the error goes away and it functions as expected.outputs:
@bioball commented on GitHub (Mar 14, 2024):
Thanks! Looks like default value for the
moduletype does not work.