mirror of
https://github.com/enso-org/enso.git
synced 2024-12-23 10:42:05 +03:00
Re-fetch Warnings in Warning.getWarnings() to correctly wrap them (#9011)
This commit is contained in:
parent
04161b33e4
commit
3bdd1a0dce
@ -106,6 +106,20 @@ public final class WithWarnings implements EnsoObject {
|
||||
value, ctx.getWarningsLimit(), warnings, newWarnings.toArray(Warning[]::new));
|
||||
}
|
||||
|
||||
// Ignore the warnings cache in .value and re-fetch them using the WarningsLibrary.
|
||||
// This is only used for shouldWrap=true.
|
||||
private Warning[] getWarningsNoCache(WarningsLibrary warningsLibrary) {
|
||||
if (warningsLibrary != null && warningsLibrary.hasWarnings(value)) {
|
||||
try {
|
||||
return warningsLibrary.getWarnings(value, null, true);
|
||||
} catch (UnsupportedMessageException e) {
|
||||
throw EnsoContext.get(warningsLibrary).raiseAssertionPanic(warningsLibrary, null, e);
|
||||
}
|
||||
} else {
|
||||
return Warning.fromSetToArray(warnings);
|
||||
}
|
||||
}
|
||||
|
||||
public Warning[] getWarningsArray(WarningsLibrary warningsLibrary, boolean shouldWrap) {
|
||||
Warning[] allWarnings;
|
||||
if (warningsLibrary != null && warningsLibrary.hasWarnings(value)) {
|
||||
@ -182,7 +196,13 @@ public final class WithWarnings implements EnsoObject {
|
||||
if (location != null) {
|
||||
return getReassignedWarnings(location, shouldWrap, warningsLibrary);
|
||||
} else {
|
||||
return Warning.fromSetToArray(warnings);
|
||||
if (shouldWrap) {
|
||||
// In the wrapping case, we don't use the local cache in .values, since
|
||||
// it contains unwrapped warnings. Instead, we fetch them again.
|
||||
return getWarningsNoCache(warningsLibrary);
|
||||
} else {
|
||||
return Warning.fromSetToArray(warnings);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -308,7 +308,7 @@ add_specs suite_builder = suite_builder.group "Dataflow Warnings" group_builder-
|
||||
r.should_equal [0, 1, 20, 3, 40, 5, 60, 7, 80, 9]
|
||||
Warning.get_all r wrap_errors=True . map .value . should_contain_the_same_elements_as [Map_Error.Error 1 100, Map_Error.Error 3 300, Map_Error.Error 5 500, Map_Error.Error 7 700, Map_Error.Error 9 900]
|
||||
|
||||
group_builder.specify "should be preserved after operations on multi-dimensional Vector" pending="https://github.com/enso-org/enso/issues/8910" <|
|
||||
group_builder.specify "should be preserved after operations on multi-dimensional Vector" <|
|
||||
even x = (Warning.attach x x) % 2
|
||||
nested_range_even x =
|
||||
(0.up_to x).to_vector.map even
|
||||
@ -319,6 +319,11 @@ add_specs suite_builder = suite_builder.group "Dataflow Warnings" group_builder-
|
||||
Warning.get_all res wrap_errors=True . map .value . should_equal [(Map_Error.Error 3 (Map_Error.Error 3 3)), (Map_Error.Error 3 (Map_Error.Error 2 2)), (Map_Error.Error 3 (Map_Error.Error 1 1)), (Map_Error.Error 3 (Map_Error.Error 0 0)), (Map_Error.Error 2 (Map_Error.Error 2 2)), (Map_Error.Error 2 (Map_Error.Error 1 1)), (Map_Error.Error 2 (Map_Error.Error 0 0)), (Map_Error.Error 1 (Map_Error.Error 1 1)), (Map_Error.Error 1 (Map_Error.Error 0 0)), (Map_Error.Error 0 (Map_Error.Error 0 0))]
|
||||
Warning.get_all (res.at 2) . map .value . should_equal [3, 2, 1, 0, 2, 1, 0, 1, 0, 0]
|
||||
|
||||
group_builder.specify "should wrap errors with even deeper nesting" <|
|
||||
Warning.get_all [[[Warning.attach "warning" 10]]] wrap_errors=True . map .value . should_equal [Map_Error.Error 0 (Map_Error.Error 0 (Map_Error.Error 0 "warning"))]
|
||||
Warning.get_all [[[[Warning.attach "warning" 10]]]] wrap_errors=True . map .value . should_equal [Map_Error.Error 0 (Map_Error.Error 0 (Map_Error.Error 0 (Map_Error.Error 0 "warning")))]
|
||||
Warning.get_all [[[[[Warning.attach "warning" 10]]]]] wrap_errors=True . map .value . should_equal [Map_Error.Error 0 (Map_Error.Error 0 (Map_Error.Error 0 (Map_Error.Error 0 (Map_Error.Error 0 "warning"))))]
|
||||
|
||||
group_builder.specify "should be preserved over arbitrary dataflow dependencies between values introduced using `if_not_error`" <|
|
||||
a = Warning.attach "a" 1
|
||||
b = Warning.attach "b" 2
|
||||
@ -467,4 +472,3 @@ main =
|
||||
suite = Test.build suite_builder->
|
||||
add_specs suite_builder
|
||||
suite.run_with_filter
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user