mirror of
https://github.com/apple/pkl.git
synced 2026-06-24 14:26:19 +02:00
Check if receiver is a module object in relativePathTo (#1650)
Closes #1649
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
* Copyright © 2024-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.
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.pkl.core.stdlib.base;
|
||||
|
||||
import com.oracle.truffle.api.CompilerDirectives;
|
||||
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
|
||||
import com.oracle.truffle.api.dsl.Specialization;
|
||||
import java.net.URI;
|
||||
@@ -30,15 +31,16 @@ public final class ModuleClassNodes {
|
||||
@Specialization
|
||||
@TruffleBoundary
|
||||
protected VmList eval(VmObjectLike self, VmObjectLike other) {
|
||||
if (!self.isModuleObject()) {
|
||||
CompilerDirectives.transferToInterpreter();
|
||||
throw exceptionBuilder().evalError("expectedModuleAsReceiver").build();
|
||||
}
|
||||
if (!other.isModuleObject()) {
|
||||
CompilerDirectives.transferToInterpreter();
|
||||
throw exceptionBuilder().evalError("expectedModuleAsArgument").build();
|
||||
}
|
||||
var selfKey = VmUtils.getModuleInfo(self).getModuleKey();
|
||||
var selfUri = selfKey.getUri();
|
||||
|
||||
if (!other.isModuleObject()) {
|
||||
throw exceptionBuilder()
|
||||
.evalError("expectedModule")
|
||||
// No meaningful SourceSection available, in this case.
|
||||
.build();
|
||||
}
|
||||
var otherKey = VmUtils.getModuleInfo(other).getModuleKey();
|
||||
var otherUri = otherKey.getUri();
|
||||
|
||||
|
||||
@@ -203,7 +203,10 @@ Class `{0}` does not have type parameters.
|
||||
notASubclassOfTyped=\
|
||||
Class `{0}` is not a subtype of `Typed`.
|
||||
|
||||
expectedModule=\
|
||||
expectedModuleAsReceiver=\
|
||||
Expected a module as the receiver, but got an object that amends a module.
|
||||
|
||||
expectedModuleAsArgument=\
|
||||
Expected a module as argument, but got an object that amends a module.
|
||||
|
||||
wrongTypeArgumentCount=\
|
||||
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
local objectThatAmendsModule = (module) {
|
||||
// add a local property to force this into a new object amends;
|
||||
// empty object amends are optimized away.
|
||||
local qux = 1
|
||||
}
|
||||
|
||||
res = objectThatAmendsModule.relativePathTo(module)
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
local objectThatAmendsModule = (module) {
|
||||
// add a local property to force this into a new object amends;
|
||||
// empty object amends are optimized away.
|
||||
local qux = 1
|
||||
}
|
||||
|
||||
res = module.relativePathTo(objectThatAmendsModule)
|
||||
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
–– Pkl Error ––
|
||||
Expected a module as the receiver, but got an object that amends a module.
|
||||
|
||||
x | res = objectThatAmendsModule.relativePathTo(module)
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
at relativePathToNotAModule1#res (file:///$snippetsDir/input/errors/relativePathToNotAModule1.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)
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
–– Pkl Error ––
|
||||
Expected a module as argument, but got an object that amends a module.
|
||||
|
||||
x | res = module.relativePathTo(objectThatAmendsModule)
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
at relativePathToNotAModule2#res (file:///$snippetsDir/input/errors/relativePathToNotAModule2.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)
|
||||
Reference in New Issue
Block a user