Skip to content

Commit 5551858

Browse files
committed
ScriptInfo: fix big bug in the return value logic
The actual return value never got assigned to the implicit "result" output, because addReturnValue called addItem to add "result" as an output, which then mistakenly disabled the appendReturnValue flag. That flag should only be disabled when an _explicit_ output exists.
1 parent 2faeac5 commit 5551858

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/main/java/org/scijava/script/ScriptInfo.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ private void parseParam(final String param,
432432
varName = tokens[1];
433433
}
434434
final Class<?> type = scriptService.lookupClass(typeName);
435-
addItem(varName, type, attrs);
435+
addItem(varName, type, attrs, true);
436436

437437
if (ScriptModule.RETURN_VALUE.equals(varName)) {
438438
// NB: The return value variable is declared as an explicit OUTPUT.
@@ -460,11 +460,11 @@ private void checkValid(final boolean valid, final String param)
460460
private void addReturnValue() {
461461
final HashMap<String, Object> attrs = new HashMap<>();
462462
attrs.put("type", "OUTPUT");
463-
addItem(ScriptModule.RETURN_VALUE, Object.class, attrs);
463+
addItem(ScriptModule.RETURN_VALUE, Object.class, attrs, false);
464464
}
465465

466466
private <T> void addItem(final String name, final Class<T> type,
467-
final Map<String, Object> attrs)
467+
final Map<String, Object> attrs, final boolean explicit)
468468
{
469469
final DefaultMutableModuleItem<T> item =
470470
new DefaultMutableModuleItem<>(this, name, type);
@@ -477,7 +477,7 @@ private <T> void addItem(final String name, final Class<T> type,
477477
registerOutput(item);
478478
// NB: Only append the return value as an extra
479479
// output when no explicit outputs are declared.
480-
appendReturnValue = false;
480+
if (explicit) appendReturnValue = false;
481481
}
482482
}
483483

0 commit comments

Comments
 (0)