From 41e012a0f0e41201e47e508c4bfdd6930aa93533 Mon Sep 17 00:00:00 2001 From: Daniel Chao Date: Fri, 5 Jun 2026 11:27:03 -0700 Subject: [PATCH] Fix toRadixString on math.minInt (#1656) Closes #1655 --- .../java/org/pkl/core/stdlib/base/IntNodes.java | 4 ++-- .../files/LanguageSnippetTests/input/api/int.pkl | 14 +++++++++----- .../files/LanguageSnippetTests/output/api/int.pcf | 1 + 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/pkl-core/src/main/java/org/pkl/core/stdlib/base/IntNodes.java b/pkl-core/src/main/java/org/pkl/core/stdlib/base/IntNodes.java index a7750e6ed..1e69dfafc 100644 --- a/pkl-core/src/main/java/org/pkl/core/stdlib/base/IntNodes.java +++ b/pkl-core/src/main/java/org/pkl/core/stdlib/base/IntNodes.java @@ -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. @@ -190,7 +190,7 @@ public final class IntNodes { @Specialization @TruffleBoundary protected String eval(long self, long radix) { - return (self < 0 ? "-" : "") + Long.toString(Math.abs(self), (int) radix); + return Long.toString(self, (int) radix); } } diff --git a/pkl-core/src/test/files/LanguageSnippetTests/input/api/int.pkl b/pkl-core/src/test/files/LanguageSnippetTests/input/api/int.pkl index e05a9cfd8..c628e8455 100644 --- a/pkl-core/src/test/files/LanguageSnippetTests/input/api/int.pkl +++ b/pkl-core/src/test/files/LanguageSnippetTests/input/api/int.pkl @@ -1,5 +1,7 @@ amends "../snippetTest.pkl" +import "pkl:math" + facts { ["isEven"] { (-124).isEven @@ -92,7 +94,7 @@ examples { 0.floor (-0).floor } - + ["toRadixString()"] { 123.toRadixString(16) 123.toRadixString(2) @@ -101,15 +103,17 @@ examples { (-123).toRadixString(16) (-123).toRadixString(2) (-123).toRadixString(33) - + 0.toRadixString(16) 0.toRadixString(2) 0.toRadixString(33) - + (-0).toRadixString(16) (-0).toRadixString(2) (-0).toRadixString(33) - + + math.minInt.toRadixString(10) + module.catch(() -> (-123).toRadixString(-1)) module.catch(() -> (-123).toRadixString(64)) } @@ -159,7 +163,7 @@ examples { (-123).toFixed(2) 0.toFixed(3) (-0).toFixed(4) - + 123456789.toFixed(1) 123456789.toFixed(2) 123456789.toFixed(3) diff --git a/pkl-core/src/test/files/LanguageSnippetTests/output/api/int.pcf b/pkl-core/src/test/files/LanguageSnippetTests/output/api/int.pcf index 843bcb9a4..e1a7b4c07 100644 --- a/pkl-core/src/test/files/LanguageSnippetTests/output/api/int.pcf +++ b/pkl-core/src/test/files/LanguageSnippetTests/output/api/int.pcf @@ -90,6 +90,7 @@ examples { "0" "0" "0" + "-9223372036854775808" "Type constraint `this.isBetween(2, 36)` violated. Value: -1" "Type constraint `this.isBetween(2, 36)` violated. Value: 64" }