mirror of
https://github.com/apple/pkl.git
synced 2026-04-24 01:08:34 +02:00
Fix Function.toString (#1411)
Fixes an issue where the underlying default Java toString() is leaking through
This commit is contained in:
@@ -138,7 +138,7 @@ Things to watch out for when upgrading.
|
|||||||
|
|
||||||
The following bugs have been fixed.
|
The following bugs have been fixed.
|
||||||
|
|
||||||
* XXX (https://github.com/apple/pkl/issues/XXX[XXX])
|
* Incorrect Function.toString() (https://github.com/apple/pkl/issues/1410[#1410])
|
||||||
|
|
||||||
== Contributors [small]#🙏#
|
== Contributors [small]#🙏#
|
||||||
|
|
||||||
|
|||||||
@@ -181,4 +181,10 @@ public final class VmFunction extends VmObjectLike {
|
|||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return System.identityHashCode(this);
|
return System.identityHashCode(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@TruffleBoundary
|
||||||
|
public String toString() {
|
||||||
|
return VmValueRenderer.singleLine(Integer.MAX_VALUE).render(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright © 2024-2025 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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -34,8 +34,13 @@ public final class VmValueRenderer {
|
|||||||
private final String interiorNewline;
|
private final String interiorNewline;
|
||||||
private final String indent;
|
private final String indent;
|
||||||
private String currIndent = "";
|
private String currIndent = "";
|
||||||
|
private static final VmValueRenderer maxSingleLine =
|
||||||
|
new VmValueRenderer(Integer.MAX_VALUE, " ", "; ", "");
|
||||||
|
|
||||||
public static VmValueRenderer singleLine(int lengthLimit) {
|
public static VmValueRenderer singleLine(int lengthLimit) {
|
||||||
|
if (lengthLimit == Integer.MAX_VALUE) {
|
||||||
|
return maxSingleLine;
|
||||||
|
}
|
||||||
return new VmValueRenderer(lengthLimit, " ", "; ", "");
|
return new VmValueRenderer(lengthLimit, " ", "; ", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -43,6 +43,10 @@ examples {
|
|||||||
"\(new Person2 { name = "Pigeon"; age = 42 })"
|
"\(new Person2 { name = "Pigeon"; age = 42 })"
|
||||||
"\(null)"
|
"\(null)"
|
||||||
"\(Null(new Person { name = "Pigeon"; age = 42 }))"
|
"\(Null(new Person { name = "Pigeon"; age = 42 }))"
|
||||||
|
"\(() -> null)"
|
||||||
|
"\((p1) -> null)"
|
||||||
|
"\((p1, p2) -> null)"
|
||||||
|
"\((p1, p2, p3) -> null)"
|
||||||
}
|
}
|
||||||
|
|
||||||
["escaping"] {
|
["escaping"] {
|
||||||
|
|||||||
@@ -9,4 +9,7 @@ res3 = even.apply(11)
|
|||||||
|
|
||||||
local mult = (x, y) -> x * y
|
local mult = (x, y) -> x * y
|
||||||
|
|
||||||
res4 = mult.apply(2, 3)
|
res4 = mult.apply(2, 3)
|
||||||
|
|
||||||
|
res5 = even.toString()
|
||||||
|
res6 = mult.toString()
|
||||||
|
|||||||
@@ -34,6 +34,10 @@ examples {
|
|||||||
"My name is Pigeon and I'm 42 years old."
|
"My name is Pigeon and I'm 42 years old."
|
||||||
"null"
|
"null"
|
||||||
"null"
|
"null"
|
||||||
|
"new Function0 {}"
|
||||||
|
"new Function1 {}"
|
||||||
|
"new Function2 {}"
|
||||||
|
"new Function3 {}"
|
||||||
}
|
}
|
||||||
["escaping"] {
|
["escaping"] {
|
||||||
"\\\"\\("
|
"\\\"\\("
|
||||||
|
|||||||
@@ -2,3 +2,5 @@ res1 = "abc"
|
|||||||
res2 = true
|
res2 = true
|
||||||
res3 = false
|
res3 = false
|
||||||
res4 = 6
|
res4 = 6
|
||||||
|
res5 = "new Function1 {}"
|
||||||
|
res6 = "new Function2 {}"
|
||||||
|
|||||||
Reference in New Issue
Block a user