mirror of
https://github.com/apple/pkl.git
synced 2026-05-28 01:29:15 +02:00
Require references from typealiases to be const (#516)
This adds a language change that requires references from typealiases to the enclosing module to be `const`. This is required because typealiases are not late-bound. Rationale is laid out in SPICE-0007. Also: * Update documentation to reflect new rules. * Fix `Project.pkl`; mark method `const` to not break said rule.
This commit is contained in:
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
typealias MyValue = Any(isValid)
|
||||
|
||||
isValid = true
|
||||
|
||||
myValue: MyValue = 1
|
||||
Vendored
+18
@@ -0,0 +1,18 @@
|
||||
–– Pkl Error ––
|
||||
Cannot reference property `isValid` from here because it is not `const`.
|
||||
|
||||
x | typealias MyValue = Any(isValid)
|
||||
^^^^^^^
|
||||
at constTypeAliasConstraint#myValue (file:///$snippetsDir/input/errors/const/constTypeAliasConstraint.pkl)
|
||||
|
||||
To fix, do either of:
|
||||
1. Add modifier `const` to property `isValid`
|
||||
2. Self-import this module, and reference this property from the import.
|
||||
|
||||
x | myValue: MyValue = 1
|
||||
^
|
||||
at constTypeAliasConstraint#myValue (file:///$snippetsDir/input/errors/const/constTypeAliasConstraint.pkl)
|
||||
|
||||
xxx | text = renderer.renderDocument(value)
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
at pkl.base#Module.output.text (pkl:base)
|
||||
Reference in New Issue
Block a user