Fix pkl:test fact power assertions when member source section is unavailable (#1571)

Power assertions only work when the source section is available. If it
is unavailable, power assertions throw a ParserError (unexpected EOF on
an empty input) when re-parsing the expression for presentation.
This commit is contained in:
Jen Basch
2026-05-04 12:25:15 -07:00
committed by GitHub
parent 9c1a9cb4f8
commit b7ba6a8649
3 changed files with 33 additions and 1 deletions
@@ -30,6 +30,7 @@ import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import org.pkl.core.PklBugException;
import org.pkl.core.ast.ConstantValueNode;
import org.pkl.core.ast.expression.member.InferParentWithinMethodNode;
import org.pkl.core.ast.expression.member.InferParentWithinObjectMethodNode;
@@ -83,6 +84,10 @@ public class PowerAssertions {
SourceSection sourceSection,
Map<Node, List<Object>> trackedValues,
@Nullable Consumer<AnsiStringBuilder> firstFrameSuffix) {
if (!sourceSection.isAvailable()) {
throw new PklBugException("Power assertions require an available source section");
}
out.appendSandboxed(
() -> {
var lines = lines(sourceSection);
@@ -102,7 +102,7 @@ public final class TestRunner {
try {
var factValue = VmUtils.readMember(listing, idx);
if (factValue == Boolean.FALSE) {
if (PowerAssertions.isEnabled()) {
if (PowerAssertions.isEnabled() && member.getSourceSection().isAvailable()) {
try (var valueTracker = valueTrackerFactory.create()) {
listing.cachedValues.clear();
VmUtils.readMember(listing, idx);