From ad9d0e5ab57fea9a965b9743c157554d2028a67e Mon Sep 17 00:00:00 2001 From: Jaroslav Tulach Date: Wed, 20 Nov 2024 09:14:38 +0100 Subject: [PATCH] Allow (42 : Text & Integer) at the end of function (#11588) Bypassing failing check. --- .../pass/resolve/TypeSignatures.scala | 2 +- .../enso/interpreter/test/SignatureTest.java | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/resolve/TypeSignatures.scala b/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/resolve/TypeSignatures.scala index 0d608c1a329..7dbad529547 100644 --- a/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/resolve/TypeSignatures.scala +++ b/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/resolve/TypeSignatures.scala @@ -318,7 +318,7 @@ case object TypeSignatures extends IRPass { case a => Some(resolveExpression(a)) } ::: lastSignature .map({ - case asc @ Type.Ascription(_: Name, sig, comment, _, _) => + case asc @ Type.Ascription(_, sig, comment, _, _) => asc.updateMetadata( new MetadataPair(this, Signature(sig, comment)) ) diff --git a/engine/runtime-integration-tests/src/test/java/org/enso/interpreter/test/SignatureTest.java b/engine/runtime-integration-tests/src/test/java/org/enso/interpreter/test/SignatureTest.java index 93353d57d58..5d9521f1127 100644 --- a/engine/runtime-integration-tests/src/test/java/org/enso/interpreter/test/SignatureTest.java +++ b/engine/runtime-integration-tests/src/test/java/org/enso/interpreter/test/SignatureTest.java @@ -1026,6 +1026,30 @@ public class SignatureTest extends ContextTest { } } + @Test + public void returnTypeCheckByLastStatementOfMain() throws Exception { + final URI uri = new URI("memory://rts.enso"); + final Source src = + Source.newBuilder( + "enso", + """ + from Standard.Base import all + + fn = + (42 : Text & Integer) + + Text.from (that:Integer) = that.to_text + """, + uri.getAuthority()) + .uri(uri) + .buildLiteral(); + + var module = ctx.eval(src); + var main = module.invokeMember(MethodNames.Module.EVAL_EXPRESSION, "fn"); + assertEquals(42, main.asInt()); + assertEquals("42", main.asString()); + } + /** * Similar scenario to {@code returnTypeCheckOptInError}, but with the opt out signature the check * is not currently performed.