Giter VIP home page Giter VIP logo

Comments (4)

stackoverflow avatar stackoverflow commented on June 3, 2024

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.

philippemerle avatar philippemerle commented on June 3, 2024

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.

bioball avatar bioball commented on June 3, 2024

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.

bioball avatar bioball commented on June 3, 2024

Closing as not planned, as this works as-intended.

from pkl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.