Skip to content

Commit

Permalink
Print out warnings for REPL return value too
Browse files Browse the repository at this point in the history
  • Loading branch information
JaroslavTulach committed Aug 20, 2024
1 parent 47c4e68 commit 49d535b
Showing 1 changed file with 26 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,25 +151,7 @@ private Object readValue(
MaterializedFrame frame, FramePointer ptr, boolean onlyWarningsOrErrors) {
var raw = getProperFrame(frame, ptr).getValue(ptr.frameSlotIdx());
if (WarningsLibrary.getUncached().hasWarnings(raw)) {
try {
var sb = new StringBuilder();
sb.append(WarningsLibrary.getUncached().removeWarnings(raw));
var mappedWarnings = WarningsLibrary.getUncached().getWarnings(raw, true);
var pairs = HashMapToVectorNode.getUncached().execute(mappedWarnings);
var size = ArrayLikeLengthNode.getUncached().executeLength(pairs);
for (var i = 0L; i < size; i++) {
try {
var pair = ArrayLikeAtNode.getUncached().executeAt(pairs, i);
var value = ArrayLikeAtNode.getUncached().executeAt(pair, 1);
sb.append("\n ! ").append(value);
} catch (InvalidArrayIndexException ex) {
// go on
}
}
return sb.toString();
} catch (UnsupportedMessageException e) {
// go on
}
return formatObject(raw);
}
if (onlyWarningsOrErrors) {
if (!InteropLibrary.getUncached().isException(raw)) {
Expand Down Expand Up @@ -234,12 +216,32 @@ public Either<Exception, String> showObject(Object object) {
}
}

private Object formatObject(Object o) {
if (o instanceof Text) {
return toJavaStringNode.execute((Text) o);
} else {
return o;
private Object formatObject(Object raw) {
if (raw instanceof Text) {
return toJavaStringNode.execute((Text) raw);
}
if (WarningsLibrary.getUncached().hasWarnings(raw)) {
try {
var sb = new StringBuilder();
sb.append(WarningsLibrary.getUncached().removeWarnings(raw));
var mappedWarnings = WarningsLibrary.getUncached().getWarnings(raw, true);
var pairs = HashMapToVectorNode.getUncached().execute(mappedWarnings);
var size = ArrayLikeLengthNode.getUncached().executeLength(pairs);
for (var i = 0L; i < size; i++) {
try {
var pair = ArrayLikeAtNode.getUncached().executeAt(pairs, i);
var value = ArrayLikeAtNode.getUncached().executeAt(pair, 1);
sb.append("\n ! ").append(value);
} catch (InvalidArrayIndexException ex) {
// go on
}
}
return sb.toString();
} catch (UnsupportedMessageException e) {
// go on
}
}
return raw;
}

@Override
Expand Down

0 comments on commit 49d535b

Please sign in to comment.