From a06c672db5f5842871d0950fefb0b714dbb84727 Mon Sep 17 00:00:00 2001 From: Pavel Marek Date: Fri, 15 Nov 2024 19:28:52 +0100 Subject: [PATCH] Warning exports WarningsLibrary --- .../enso/interpreter/test/WarningsTest.java | 9 ++++++++ .../interpreter/runtime/warning/Warning.java | 22 +++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/engine/runtime-integration-tests/src/test/java/org/enso/interpreter/test/WarningsTest.java b/engine/runtime-integration-tests/src/test/java/org/enso/interpreter/test/WarningsTest.java index 61aead7772e..2a0d50d473e 100644 --- a/engine/runtime-integration-tests/src/test/java/org/enso/interpreter/test/WarningsTest.java +++ b/engine/runtime-integration-tests/src/test/java/org/enso/interpreter/test/WarningsTest.java @@ -2,6 +2,7 @@ package org.enso.interpreter.test; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @@ -12,6 +13,7 @@ import org.enso.common.MethodNames; import org.enso.interpreter.runtime.EnsoContext; import org.enso.interpreter.runtime.warning.AppendWarningNode; import org.enso.interpreter.runtime.warning.Warning; +import org.enso.interpreter.runtime.warning.WarningsLibrary; import org.enso.interpreter.runtime.warning.WithWarnings; import org.enso.test.utils.ContextUtils; import org.graalvm.polyglot.Context; @@ -194,4 +196,11 @@ public class WarningsTest { assertEquals( "Standard.Base.Error.Error", errorWithWarning.getMetaObject().getMetaQualifiedName()); } + + @Test + public void warningIsWarning_ViaWarningsLibrary() { + var warn = wrap.execute("Warning", 42L); + var warnsLib = WarningsLibrary.getUncached(); + assertThat(warnsLib.hasWarnings(warn), is(true)); + } } diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/warning/Warning.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/warning/Warning.java index b6025eb2abd..a8cf0c8047f 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/warning/Warning.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/warning/Warning.java @@ -20,6 +20,7 @@ import org.enso.interpreter.runtime.library.dispatch.TypesLibrary; @Builtin(pkg = "error", stdlibName = "Standard.Base.Warning.Warning") @ExportLibrary(TypesLibrary.class) +@ExportLibrary(WarningsLibrary.class) @ExportLibrary(value = InteropLibrary.class, delegateTo = "value") public final class Warning extends EnsoObject { final Object value; @@ -133,6 +134,27 @@ public final class Warning extends EnsoObject { return EnsoContext.get(node).getBuiltins().warning(); } + @ExportMessage + boolean hasWarnings() { + return true; + } + + @ExportMessage + EnsoHashMap getWarnings(boolean shouldWrap, @Cached HashMapInsertNode insertNode) { + var map = insertNode.execute(null, EnsoHashMap.empty(), 0, this); + return map; + } + + @ExportMessage + Object removeWarnings() throws UnsupportedMessageException { + throw UnsupportedMessageException.create(); + } + + @ExportMessage + boolean isLimitReached() { + return true; + } + public static Warning wrapMapError(WarningsLibrary warningsLib, Warning warning, long index) { var ctx = EnsoContext.get(warningsLib); var error = warning.getValue();