From 1f5c62eceffeaf93f93c483e28540b58258aa00e Mon Sep 17 00:00:00 2001 From: Daniel Chao Date: Wed, 4 Nov 2026 11:30:50 -0800 Subject: [PATCH] Refine requirements around `const` and `this` type (#1962) This introduces a rule that const properties cannot use the `this` type if that referenced type exceeds the scope. This code is an error: ```pkl const foo: this ``` This is not: ```pkl const foo = new { local myself: this } ``` Additionally, this fixes: * const depth logic to account for eager scopes * behavior of `this` type inside custom this scopes --- .../org/pkl/core/ast/builder/AstBuilder.java | 19 ++++++++-- .../org/pkl/core/ast/builder/SymbolTable.java | 29 ++++++++++----- .../GetCustomThisReceiverClassNode.java | 35 +++++++++++++++++++ .../org/pkl/core/errorMessages.properties | 6 ++++ .../input/errors/const/constEagerScope.pkl | 5 +++ .../input/errors/const/constEagerScope2.pkl | 7 ++++ .../input/errors/const/constExplicitThis2.pkl | 4 +++ .../input/errors/const/constForGenerator.pkl | 3 ++ .../input/types/thisType1.pkl | 3 +- .../input/types/thisType10.pkl | 6 ++++ .../input/types/thisType11.pkl | 1 + .../input/types/thisType12.pkl | 1 + .../input/types/thisType3.pkl | 15 +++++--- .../input/types/thisType4.pkl | 15 +++++--- .../input/types/thisType7.pkl | 1 + .../input/types/thisType8.pkl | 1 + .../input/types/thisType9.pkl | 14 ++++++++ .../output/errors/const/constEagerScope.err | 18 ++++++++++ .../output/errors/const/constEagerScope2.err | 18 ++++++++++ .../errors/const/constExplicitThis2.err | 22 ++++++++++++ .../output/errors/const/constForGenerator.err | 18 ++++++++++ .../output/types/thisType10.err | 6 ++++ .../output/types/thisType11.err | 6 ++++ .../output/types/thisType12.pcf | 1 + .../output/types/thisType3.pcf | 14 +++++--- .../output/types/thisType4.pcf | 14 +++++--- .../output/types/thisType7.err | 6 ++++ .../output/types/thisType8.err | 6 ++++ .../output/types/thisType9.pcf | 8 +++++ 29 files changed, 273 insertions(+), 29 deletions(-) create mode 100644 pkl-core/src/main/java/org/pkl/core/ast/expression/primary/GetCustomThisReceiverClassNode.java create mode 100644 pkl-core/src/test/files/LanguageSnippetTests/input/errors/const/constEagerScope.pkl create mode 100644 pkl-core/src/test/files/LanguageSnippetTests/input/errors/const/constEagerScope2.pkl create mode 100644 pkl-core/src/test/files/LanguageSnippetTests/input/errors/const/constExplicitThis2.pkl create mode 100644 pkl-core/src/test/files/LanguageSnippetTests/input/errors/const/constForGenerator.pkl create mode 100644 pkl-core/src/test/files/LanguageSnippetTests/input/types/thisType10.pkl create mode 100644 pkl-core/src/test/files/LanguageSnippetTests/input/types/thisType11.pkl create mode 100644 pkl-core/src/test/files/LanguageSnippetTests/input/types/thisType12.pkl create mode 100644 pkl-core/src/test/files/LanguageSnippetTests/input/types/thisType7.pkl create mode 100644 pkl-core/src/test/files/LanguageSnippetTests/input/types/thisType8.pkl create mode 100644 pkl-core/src/test/files/LanguageSnippetTests/input/types/thisType9.pkl create mode 100644 pkl-core/src/test/files/LanguageSnippetTests/output/errors/const/constEagerScope.err create mode 100644 pkl-core/src/test/files/LanguageSnippetTests/output/errors/const/constEagerScope2.err create mode 100644 pkl-core/src/test/files/LanguageSnippetTests/output/errors/const/constExplicitThis2.err create mode 100644 pkl-core/src/test/files/LanguageSnippetTests/output/errors/const/constForGenerator.err create mode 100644 pkl-core/src/test/files/LanguageSnippetTests/output/types/thisType10.err create mode 100644 pkl-core/src/test/files/LanguageSnippetTests/output/types/thisType11.err create mode 100644 pkl-core/src/test/files/LanguageSnippetTests/output/types/thisType12.pcf create mode 100644 pkl-core/src/test/files/LanguageSnippetTests/output/types/thisType7.err create mode 100644 pkl-core/src/test/files/LanguageSnippetTests/output/types/thisType8.err create mode 100644 pkl-core/src/test/files/LanguageSnippetTests/output/types/thisType9.pcf diff --git a/pkl-core/src/main/java/org/pkl/core/ast/builder/AstBuilder.java b/pkl-core/src/main/java/org/pkl/core/ast/builder/AstBuilder.java index 2e9aa1473..24f9a77ab 100644 --- a/pkl-core/src/main/java/org/pkl/core/ast/builder/AstBuilder.java +++ b/pkl-core/src/main/java/org/pkl/core/ast/builder/AstBuilder.java @@ -125,6 +125,7 @@ import org.pkl.core.ast.expression.member.ReadQualifiedLocalPropertyNode; import org.pkl.core.ast.expression.member.ReadSuperEntryNodeGen; import org.pkl.core.ast.expression.member.ReadSuperPropertyNodeGen; import org.pkl.core.ast.expression.primary.ExecuteCustomThisWithRootNode; +import org.pkl.core.ast.expression.primary.GetCustomThisReceiverClassNode; import org.pkl.core.ast.expression.primary.GetEnclosingReceiverNode; import org.pkl.core.ast.expression.primary.GetMemberKeyNode; import org.pkl.core.ast.expression.primary.GetModuleNode; @@ -434,13 +435,24 @@ public class AstBuilder extends AbstractAstBuilder { @Override public UnresolvedTypeNode visitThisType(ThisType type) { var sourceSection = createSourceSection(type); + var currentScope = symbolTable.getCurrentScope(); + if (!currentScope.isCustomThisScope() + && currentScope.getConstLevel() == ConstLevel.ALL + && currentScope.getConstDepth() == -1) { + var message = + currentScope.isPropertyScope() ? "invalidThisTypeInProperty" : "invalidThisTypeInMethod"; + throw exceptionBuilder() + .evalError(message, currentScope.getQualifiedName()) + .withSourceSection(sourceSection) + .build(); + } // need to pass explicit class name for property and method arg/return type annotations. // this is because type annotations on class properties/methods are initialized when the // ClassNode // is executed, and the frame's receiver is the enclosing module rather than the class. // do not need: when in any object or at the module level (where `this` is the receiver's class) org.pkl.core.runtime.Identifier className = null; - for (var scope = symbolTable.getCurrentScope(); scope != null; scope = scope.getParent()) { + for (var scope = currentScope; scope != null; scope = scope.getParent()) { if (scope.isObjectScope() || scope.isCustomThisScope()) { break; } @@ -462,7 +474,10 @@ public class AstBuilder extends AbstractAstBuilder { if (isBaseModule && className != null) { getClassNode = new GetBaseModuleClassNode(className); } else if (className == null) { - getClassNode = new GetReceiverClassNode(sourceSection); + getClassNode = + currentScope.isCustomThisScope() + ? new GetCustomThisReceiverClassNode(sourceSection) + : new GetReceiverClassNode(sourceSection); } else if (className.isLocalProp()) { getClassNode = new ReadQualifiedLocalPropertyNode( diff --git a/pkl-core/src/main/java/org/pkl/core/ast/builder/SymbolTable.java b/pkl-core/src/main/java/org/pkl/core/ast/builder/SymbolTable.java index a04e76fce..b2ea30b33 100644 --- a/pkl-core/src/main/java/org/pkl/core/ast/builder/SymbolTable.java +++ b/pkl-core/src/main/java/org/pkl/core/ast/builder/SymbolTable.java @@ -355,18 +355,29 @@ public final class SymbolTable { */ public int getConstDepth() { var depth = -1; - var lexicalScope = getLexicalScope(); - while (lexicalScope.getConstLevel() == ConstLevel.ALL) { + var skipObjectBody = false; + for (var scope = this; + scope != null && scope.getConstLevel() == ConstLevel.ALL; + scope = scope.getParent()) { + if (scope instanceof EagerGeneratorScope) { + skipObjectBody = true; + continue; + } // LambdaScope inherits constLevel but doesn't create a const scope barrier. - // Method scopes don't level up. - if (!(lexicalScope instanceof LambdaScope) && !(lexicalScope instanceof MethodScope)) { + // Method scopes, let expression scopes, and for generator scopes don't level up. + if (scope instanceof LambdaScope + || scope instanceof MethodScope + || scope instanceof LetExpressionScope + || scope instanceof ForGeneratorScope) { + continue; + } + if (scope instanceof LexicalScope) { + if (scope instanceof ObjectScope && skipObjectBody) { + skipObjectBody = false; + continue; + } depth += 1; } - var parent = lexicalScope.getParent(); - if (parent == null) { - return depth; - } - lexicalScope = parent.getLexicalScope(); } return depth; } diff --git a/pkl-core/src/main/java/org/pkl/core/ast/expression/primary/GetCustomThisReceiverClassNode.java b/pkl-core/src/main/java/org/pkl/core/ast/expression/primary/GetCustomThisReceiverClassNode.java new file mode 100644 index 000000000..c3aeb5d74 --- /dev/null +++ b/pkl-core/src/main/java/org/pkl/core/ast/expression/primary/GetCustomThisReceiverClassNode.java @@ -0,0 +1,35 @@ +/* + * Copyright © 2026 Apple Inc. and the Pkl project authors. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.pkl.core.ast.expression.primary; + +import com.oracle.truffle.api.frame.VirtualFrame; +import com.oracle.truffle.api.source.SourceSection; +import org.pkl.core.ast.ExpressionNode; +import org.pkl.core.runtime.VmUtils; + +public class GetCustomThisReceiverClassNode extends ExpressionNode { + @Child ExpressionNode customThisNode; + + public GetCustomThisReceiverClassNode(SourceSection sourceSection) { + this.customThisNode = new CustomThisNode(sourceSection); + } + + @Override + public Object executeGeneric(VirtualFrame frame) { + var receiver = customThisNode.executeGeneric(frame); + return VmUtils.getClass(receiver); + } +} diff --git a/pkl-core/src/main/resources/org/pkl/core/errorMessages.properties b/pkl-core/src/main/resources/org/pkl/core/errorMessages.properties index 4127c5d68..92fe938b2 100644 --- a/pkl-core/src/main/resources/org/pkl/core/errorMessages.properties +++ b/pkl-core/src/main/resources/org/pkl/core/errorMessages.properties @@ -1283,5 +1283,11 @@ Cannot reference `module` type within a type alias body. invalidThisTypeInTypeAlias=\ Cannot reference `this` type within a type alias body. +invalidThisTypeInProperty=\ +Cannot reference `this` type from const property `{0}`. + +invalidThisTypeInMethod=\ +Cannot reference `this` type from const method `{0}`. + cannotParseNetrc=\ Cannot parse .netrc: {0}. diff --git a/pkl-core/src/test/files/LanguageSnippetTests/input/errors/const/constEagerScope.pkl b/pkl-core/src/test/files/LanguageSnippetTests/input/errors/const/constEagerScope.pkl new file mode 100644 index 000000000..95b56c6b5 --- /dev/null +++ b/pkl-core/src/test/files/LanguageSnippetTests/input/errors/const/constEagerScope.pkl @@ -0,0 +1,5 @@ +key = "hello" + +const result = new { + [this.key] = "world" +} diff --git a/pkl-core/src/test/files/LanguageSnippetTests/input/errors/const/constEagerScope2.pkl b/pkl-core/src/test/files/LanguageSnippetTests/input/errors/const/constEagerScope2.pkl new file mode 100644 index 000000000..a89f7ea0f --- /dev/null +++ b/pkl-core/src/test/files/LanguageSnippetTests/input/errors/const/constEagerScope2.pkl @@ -0,0 +1,7 @@ +key = List("hello", "world") + +const result = new { + for (key in this.key) { + key + } +} diff --git a/pkl-core/src/test/files/LanguageSnippetTests/input/errors/const/constExplicitThis2.pkl b/pkl-core/src/test/files/LanguageSnippetTests/input/errors/const/constExplicitThis2.pkl new file mode 100644 index 000000000..49b7030a1 --- /dev/null +++ b/pkl-core/src/test/files/LanguageSnippetTests/input/errors/const/constExplicitThis2.pkl @@ -0,0 +1,4 @@ +baz = 1 + +// no error +const foo = let (x = 1) this.baz diff --git a/pkl-core/src/test/files/LanguageSnippetTests/input/errors/const/constForGenerator.pkl b/pkl-core/src/test/files/LanguageSnippetTests/input/errors/const/constForGenerator.pkl new file mode 100644 index 000000000..6e3c3bbb1 --- /dev/null +++ b/pkl-core/src/test/files/LanguageSnippetTests/input/errors/const/constForGenerator.pkl @@ -0,0 +1,3 @@ +baz = 1 + +const foo = new Listing { for (i in List(1)) { baz } } diff --git a/pkl-core/src/test/files/LanguageSnippetTests/input/types/thisType1.pkl b/pkl-core/src/test/files/LanguageSnippetTests/input/types/thisType1.pkl index fb1eb2888..7b50cbb1e 100644 --- a/pkl-core/src/test/files/LanguageSnippetTests/input/types/thisType1.pkl +++ b/pkl-core/src/test/files/LanguageSnippetTests/input/types/thisType1.pkl @@ -58,8 +58,7 @@ res11d = res11.res6a.x res12 = test.catch(() -> res11.fun(module)[0].x) -// this type not affected by custom this scope: -hidden res13: List(this is List) = List(module) +hidden res13: List(this is this) = List(module) res13a = res13[0].x // test generic typealias through inheritance from module diff --git a/pkl-core/src/test/files/LanguageSnippetTests/input/types/thisType10.pkl b/pkl-core/src/test/files/LanguageSnippetTests/input/types/thisType10.pkl new file mode 100644 index 000000000..a3667fb3c --- /dev/null +++ b/pkl-core/src/test/files/LanguageSnippetTests/input/types/thisType10.pkl @@ -0,0 +1,6 @@ +qux = "qux" + +const foo = new { + // `myself` here is the module; this escapes the const scope + [let (myself: this = this) myself.qux] = 5 +} diff --git a/pkl-core/src/test/files/LanguageSnippetTests/input/types/thisType11.pkl b/pkl-core/src/test/files/LanguageSnippetTests/input/types/thisType11.pkl new file mode 100644 index 000000000..c41e4cded --- /dev/null +++ b/pkl-core/src/test/files/LanguageSnippetTests/input/types/thisType11.pkl @@ -0,0 +1 @@ +const func = (elem: this) -> elem diff --git a/pkl-core/src/test/files/LanguageSnippetTests/input/types/thisType12.pkl b/pkl-core/src/test/files/LanguageSnippetTests/input/types/thisType12.pkl new file mode 100644 index 000000000..0c1d9fcf0 --- /dev/null +++ b/pkl-core/src/test/files/LanguageSnippetTests/input/types/thisType12.pkl @@ -0,0 +1 @@ +const foo: String(this is this) = "x" diff --git a/pkl-core/src/test/files/LanguageSnippetTests/input/types/thisType3.pkl b/pkl-core/src/test/files/LanguageSnippetTests/input/types/thisType3.pkl index 1310596d2..0505e0934 100644 --- a/pkl-core/src/test/files/LanguageSnippetTests/input/types/thisType3.pkl +++ b/pkl-core/src/test/files/LanguageSnippetTests/input/types/thisType3.pkl @@ -7,15 +7,22 @@ res1 = foo.length local baz: Listing = new { new Listing { "hello" } new Mapping { ["hello"] = "world" } - module } res2 = (baz) { - [[this is this]] { - res2 = "blah" - } when (module is this) { 123 } module is this } + +local res3: Listing> = new { + new { "one" } + new { "two" } +} + +res4 = (res3) { + [[this is this]] { + "three" + } +} diff --git a/pkl-core/src/test/files/LanguageSnippetTests/input/types/thisType4.pkl b/pkl-core/src/test/files/LanguageSnippetTests/input/types/thisType4.pkl index 815977a9f..db25c2b6b 100644 --- a/pkl-core/src/test/files/LanguageSnippetTests/input/types/thisType4.pkl +++ b/pkl-core/src/test/files/LanguageSnippetTests/input/types/thisType4.pkl @@ -8,15 +8,22 @@ res1 = foo.length local baz: Listing = new { new Listing { "hello" } new Mapping { ["hello"] = "world" } - module } res2 = (baz) { - [[this is this]] { - res2 = "blah" - } when (module is this) { 123 } module is this } + +local res3: Listing> = new { + new { "one" } + new { "two" } +} + +res4 = (res3) { + [[this is this]] { + "three" + } +} diff --git a/pkl-core/src/test/files/LanguageSnippetTests/input/types/thisType7.pkl b/pkl-core/src/test/files/LanguageSnippetTests/input/types/thisType7.pkl new file mode 100644 index 000000000..fa2d43a6d --- /dev/null +++ b/pkl-core/src/test/files/LanguageSnippetTests/input/types/thisType7.pkl @@ -0,0 +1 @@ +const foo: this diff --git a/pkl-core/src/test/files/LanguageSnippetTests/input/types/thisType8.pkl b/pkl-core/src/test/files/LanguageSnippetTests/input/types/thisType8.pkl new file mode 100644 index 000000000..6843c941a --- /dev/null +++ b/pkl-core/src/test/files/LanguageSnippetTests/input/types/thisType8.pkl @@ -0,0 +1 @@ +const function foo(bar: this) = 1 diff --git a/pkl-core/src/test/files/LanguageSnippetTests/input/types/thisType9.pkl b/pkl-core/src/test/files/LanguageSnippetTests/input/types/thisType9.pkl new file mode 100644 index 000000000..89d633eae --- /dev/null +++ b/pkl-core/src/test/files/LanguageSnippetTests/input/types/thisType9.pkl @@ -0,0 +1,14 @@ +// okay to use `this` if it doesn't break the const scope +const function myFunc() = new { + local myself: this = this + result = myself.bar + bar = 3 +} + +const res1 = new { + local myself: this = this + result = myself.bar + bar = 3 +} + +res2 = myFunc() diff --git a/pkl-core/src/test/files/LanguageSnippetTests/output/errors/const/constEagerScope.err b/pkl-core/src/test/files/LanguageSnippetTests/output/errors/const/constEagerScope.err new file mode 100644 index 000000000..034a82a0a --- /dev/null +++ b/pkl-core/src/test/files/LanguageSnippetTests/output/errors/const/constEagerScope.err @@ -0,0 +1,18 @@ +–– Pkl Error –– +Cannot reference property `key` from here because it is not `const`. + +x | [this.key] = "world" + ^^^^^^^^ +at constEagerScope#result (file:///$snippetsDir/input/errors/const/constEagerScope.pkl) + +To fix, do either of: +1. Add modifier `const` to property `key` +2. Self-import this module, and reference this property from the import. + +xxx | renderer.renderDocument(value) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +at pkl.base#Module.output.text (pkl:base) + +xxx | if (renderer is BytesRenderer) renderer.renderDocument(value) else text.encodeToBytes("UTF-8") + ^^^^ +at pkl.base#Module.output.bytes (pkl:base) diff --git a/pkl-core/src/test/files/LanguageSnippetTests/output/errors/const/constEagerScope2.err b/pkl-core/src/test/files/LanguageSnippetTests/output/errors/const/constEagerScope2.err new file mode 100644 index 000000000..37ebf81da --- /dev/null +++ b/pkl-core/src/test/files/LanguageSnippetTests/output/errors/const/constEagerScope2.err @@ -0,0 +1,18 @@ +–– Pkl Error –– +Cannot reference property `key` from here because it is not `const`. + +x | for (key in this.key) { + ^^^^^^^^ +at constEagerScope2#result (file:///$snippetsDir/input/errors/const/constEagerScope2.pkl) + +To fix, do either of: +1. Add modifier `const` to property `key` +2. Self-import this module, and reference this property from the import. + +xxx | renderer.renderDocument(value) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +at pkl.base#Module.output.text (pkl:base) + +xxx | if (renderer is BytesRenderer) renderer.renderDocument(value) else text.encodeToBytes("UTF-8") + ^^^^ +at pkl.base#Module.output.bytes (pkl:base) diff --git a/pkl-core/src/test/files/LanguageSnippetTests/output/errors/const/constExplicitThis2.err b/pkl-core/src/test/files/LanguageSnippetTests/output/errors/const/constExplicitThis2.err new file mode 100644 index 000000000..49b8f7693 --- /dev/null +++ b/pkl-core/src/test/files/LanguageSnippetTests/output/errors/const/constExplicitThis2.err @@ -0,0 +1,22 @@ +–– Pkl Error –– +Cannot reference property `baz` from here because it is not `const`. + +x | const foo = let (x = 1) this.baz + ^^^^^^^^ +at constExplicitThis2#foo (file:///$snippetsDir/input/errors/const/constExplicitThis2.pkl) + +To fix, do either of: +1. Add modifier `const` to property `baz` +2. Self-import this module, and reference this property from the import. + +x | const foo = let (x = 1) this.baz + ^^^^^^^^^^^^^^^^^^^^ +at constExplicitThis2#foo. (file:///$snippetsDir/input/errors/const/constExplicitThis2.pkl) + +xxx | renderer.renderDocument(value) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +at pkl.base#Module.output.text (pkl:base) + +xxx | if (renderer is BytesRenderer) renderer.renderDocument(value) else text.encodeToBytes("UTF-8") + ^^^^ +at pkl.base#Module.output.bytes (pkl:base) diff --git a/pkl-core/src/test/files/LanguageSnippetTests/output/errors/const/constForGenerator.err b/pkl-core/src/test/files/LanguageSnippetTests/output/errors/const/constForGenerator.err new file mode 100644 index 000000000..3fcad1120 --- /dev/null +++ b/pkl-core/src/test/files/LanguageSnippetTests/output/errors/const/constForGenerator.err @@ -0,0 +1,18 @@ +–– Pkl Error –– +Cannot reference property `baz` from here because it is not `const`. + +x | const foo = new Listing { for (i in List(1)) { baz } } + ^^^ +at constForGenerator#foo[#1] (file:///$snippetsDir/input/errors/const/constForGenerator.pkl) + +To fix, do either of: +1. Add modifier `const` to property `baz` +2. Self-import this module, and reference this property from the import. + +xxx | renderer.renderDocument(value) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +at pkl.base#Module.output.text (pkl:base) + +xxx | if (renderer is BytesRenderer) renderer.renderDocument(value) else text.encodeToBytes("UTF-8") + ^^^^ +at pkl.base#Module.output.bytes (pkl:base) diff --git a/pkl-core/src/test/files/LanguageSnippetTests/output/types/thisType10.err b/pkl-core/src/test/files/LanguageSnippetTests/output/types/thisType10.err new file mode 100644 index 000000000..0cf29e51b --- /dev/null +++ b/pkl-core/src/test/files/LanguageSnippetTests/output/types/thisType10.err @@ -0,0 +1,6 @@ +–– Pkl Error –– +Cannot reference `this` type from const method `thisType10#foo`. + +x | [let (myself: this = this) myself.qux] = 5 + ^^^^ +at thisType10#foo (file:///$snippetsDir/input/types/thisType10.pkl) diff --git a/pkl-core/src/test/files/LanguageSnippetTests/output/types/thisType11.err b/pkl-core/src/test/files/LanguageSnippetTests/output/types/thisType11.err new file mode 100644 index 000000000..01a66d12e --- /dev/null +++ b/pkl-core/src/test/files/LanguageSnippetTests/output/types/thisType11.err @@ -0,0 +1,6 @@ +–– Pkl Error –– +Cannot reference `this` type from const method `thisType11#func.`. + +x | const func = (elem: this) -> elem + ^^^^ +at thisType11#func. (file:///$snippetsDir/input/types/thisType11.pkl) diff --git a/pkl-core/src/test/files/LanguageSnippetTests/output/types/thisType12.pcf b/pkl-core/src/test/files/LanguageSnippetTests/output/types/thisType12.pcf new file mode 100644 index 000000000..9e798f760 --- /dev/null +++ b/pkl-core/src/test/files/LanguageSnippetTests/output/types/thisType12.pcf @@ -0,0 +1 @@ +foo = "x" diff --git a/pkl-core/src/test/files/LanguageSnippetTests/output/types/thisType3.pcf b/pkl-core/src/test/files/LanguageSnippetTests/output/types/thisType3.pcf index 043504165..1a3880adf 100644 --- a/pkl-core/src/test/files/LanguageSnippetTests/output/types/thisType3.pcf +++ b/pkl-core/src/test/files/LanguageSnippetTests/output/types/thisType3.pcf @@ -6,10 +6,16 @@ res2 { new { ["hello"] = "world" } - new { - res1 = 1 - res2 = "blah" - } 123 false } +res4 { + new { + "one" + "three" + } + new { + "two" + "three" + } +} diff --git a/pkl-core/src/test/files/LanguageSnippetTests/output/types/thisType4.pcf b/pkl-core/src/test/files/LanguageSnippetTests/output/types/thisType4.pcf index 043504165..1a3880adf 100644 --- a/pkl-core/src/test/files/LanguageSnippetTests/output/types/thisType4.pcf +++ b/pkl-core/src/test/files/LanguageSnippetTests/output/types/thisType4.pcf @@ -6,10 +6,16 @@ res2 { new { ["hello"] = "world" } - new { - res1 = 1 - res2 = "blah" - } 123 false } +res4 { + new { + "one" + "three" + } + new { + "two" + "three" + } +} diff --git a/pkl-core/src/test/files/LanguageSnippetTests/output/types/thisType7.err b/pkl-core/src/test/files/LanguageSnippetTests/output/types/thisType7.err new file mode 100644 index 000000000..83d109164 --- /dev/null +++ b/pkl-core/src/test/files/LanguageSnippetTests/output/types/thisType7.err @@ -0,0 +1,6 @@ +–– Pkl Error –– +Cannot reference `this` type from const property `thisType7#foo`. + +x | const foo: this + ^^^^ +at thisType7#foo (file:///$snippetsDir/input/types/thisType7.pkl) diff --git a/pkl-core/src/test/files/LanguageSnippetTests/output/types/thisType8.err b/pkl-core/src/test/files/LanguageSnippetTests/output/types/thisType8.err new file mode 100644 index 000000000..fb0aa6c2d --- /dev/null +++ b/pkl-core/src/test/files/LanguageSnippetTests/output/types/thisType8.err @@ -0,0 +1,6 @@ +–– Pkl Error –– +Cannot reference `this` type from const method `thisType8#foo`. + +x | const function foo(bar: this) = 1 + ^^^^ +at thisType8#foo (file:///$snippetsDir/input/types/thisType8.pkl) diff --git a/pkl-core/src/test/files/LanguageSnippetTests/output/types/thisType9.pcf b/pkl-core/src/test/files/LanguageSnippetTests/output/types/thisType9.pcf new file mode 100644 index 000000000..bf9a5f3fe --- /dev/null +++ b/pkl-core/src/test/files/LanguageSnippetTests/output/types/thisType9.pcf @@ -0,0 +1,8 @@ +res1 { + result = 3 + bar = 3 +} +res2 { + result = 3 + bar = 3 +}