Comments (4)
Scoping rules in Pkl can be a bit tricky. You can use module
to reference top level variables and functions:
amends "base_template.pkl"
persons {
new Person { name = "Me"}
module.buildPerson("you")
}
Also: if you use our IntelliJ plugin you should see an error telling you this function is not found.
from pkl.
Thank you the provided solution. But this will be simpler if inherited functions could be called directly without prefixing them by module.
. Perhaps in a future pkl release?
from pkl.
The scoping rules in place here provide an important safety net; that the resolved member can't change by adding something else in the (grand)parent module.
Without this rule, it would be possible to change what a variable/method resolved to by changing something in the base module. It would make it so that adding names to a module might produce very unexpected results in the generated configuration.
For example, if this worked:
parent.pkl
function foo() = "bar"
class MyObject {
prop: String
}
obj: MyObject
child.pkl
obj {
prop = foo()
}
Then, a new function foo()
was introduced:
function foo() = "bar"
class MyObject {
prop: String
+
+ function foo() = "baz"
}
obj: MyObject
This change seems innocent when just looking at parent.pkl
, but it would change foo()
within child.pkl
to resolve to a different method. This behavior would make it too easy for pkl code to break in hidden ways.
The same resolution rules apply to properties, too.
from pkl.
Closing as not planned, as this works as-intended.
from pkl.
Related Issues (20)
- How to adopt HTTP proxy while downloading pkl packages? HOT 6
- Support for `-SNAPSHOT` versions that do not cache the package locally HOT 7
- Add Dart to supported languages HOT 1
- Templating with classes does not fail if expected HOT 5
- Support for pkldoc generation via CLI HOT 1
- Dont allow modules to be extended/amended HOT 6
- Cannot find property HOT 3
- Cannot import dynamically HOT 5
- discrepancy in Filling out a Template tutorial HOT 2
- structTags in generator-settings.pkl caused pkl-gen-go to panic HOT 2
- `project package` throws `InvalidAlgorithmParameterException` when adding `Package.apiTests` HOT 6
- Rust Language Binding HOT 9
- [Feature Request] Support / Bindings for CPS
- [feat] `module` self type allow submodule definition inline HOT 1
- How to reuse code in pkl HOT 2
- [Feature] Support badges of latest version on your package server (`pkg.pkl-lang.org`) HOT 3
- Infinite loop with same name HOT 5
- `PklProject.exclude` doesn't respect directories HOT 3
- Triple dot module uri resolution for local dependencies HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pkl.