diff --git a/aqua-src/antithesis.aqua b/aqua-src/antithesis.aqua index 33e0140e7..778e77649 100644 --- a/aqua-src/antithesis.aqua +++ b/aqua-src/antithesis.aqua @@ -1,16 +1,41 @@ -aqua StreamMapTest declares * - -export testGetFunc, Srv - -service Srv("baaa"): - g() -> string - -func testGetFunc() -> []string, []string, []string, u32: - streamMap: %string - key = "key" - resEmpty = streamMap.get(key) - streamMap <<- key, "first value" - resFirst = streamMap.get(key) - streamMap <<- key, "second value" - resSecond = streamMap.get(key) - <- resEmpty, resFirst, resSecond, resSecond.length \ No newline at end of file +aqua StreamMapAbilities + +export streamMapAbilityTest + +ability Streams: + stream: *string + map: %string + +ability Adds: + addToStream(s: string) + addToMap(k: string, v: string) + +func addToStreamClosure(str: *string) -> string -> (): + cl = func (s: string): + str <<- s + <- cl + +func addToMapClosure(str: %string) -> string, string -> (): + cl = func (k: string, v: string): + str <<- k, v + <- cl + +func addTo{Streams}() -> Adds: + addStream = addToStreamClosure(Streams.stream) + addMap = addToMapClosure(Streams.map) + adds = Adds(addToStream = addStream, addToMap = addMap) + <- adds + +func add{Adds}(s: string, k: string): + Adds.addToStream(s) + Adds.addToMap(k, k) + +func streamMapAbilityTest() -> []string, []string: + stream: *string + map: %string + ab = Streams(stream = stream, map = map) + adds <- addTo{ab}() + add{adds}("one", "1") + add{adds}("two", "2") + add{adds}("three", "3") + <- stream, map.keys() \ No newline at end of file diff --git a/integration-tests/aqua/examples/closureReturnRename.aqua b/integration-tests/aqua/examples/closureReturnRename.aqua index a86b0d124..8ed220e1a 100644 --- a/integration-tests/aqua/examples/closureReturnRename.aqua +++ b/integration-tests/aqua/examples/closureReturnRename.aqua @@ -1,6 +1,6 @@ aqua ClosureReturnRename -export lng193Bug +export lng193Bug, lng365Bug func getClosure(arg: u16, peer: string) -> u16 -> u16: on peer: @@ -16,3 +16,41 @@ func lng193Bug(peer: string, closurePeer: string) -> u16: res1 = a(1) + a(2) -- Call two times for res2 = b(3) + b(4) -- bug to appear <- res1 + res2 + +ability Streams: + stream: *string + map: %string + +ability Adds: + addToStream(s: string) + addToMap(k: string, v: string) + +func addToStreamClosure(str: *string) -> string -> (): + cl = func (s: string): + str <<- s + <- cl + +func addToMapClosure(str: %string) -> string, string -> (): + cl = func (k: string, v: string): + str <<- k, v + <- cl + +func addTo{Streams}() -> Adds: + addStream = addToStreamClosure(Streams.stream) + addMap = addToMapClosure(Streams.map) + adds = Adds(addToStream = addStream, addToMap = addMap) + <- adds + +func add{Adds}(s: string, k: string): + Adds.addToStream(s) + Adds.addToMap(k, k) + +func lng365Bug() -> []string, []string: + stream: *string + map: %string + ab = Streams(stream = stream, map = map) + adds <- addTo{ab}() + add{adds}("one", "1") + add{adds}("two", "2") + add{adds}("three", "3") + <- stream, map.keys() \ No newline at end of file diff --git a/integration-tests/src/__test__/examples.spec.ts b/integration-tests/src/__test__/examples.spec.ts index 0e90647d7..52f2eae74 100644 --- a/integration-tests/src/__test__/examples.spec.ts +++ b/integration-tests/src/__test__/examples.spec.ts @@ -141,7 +141,7 @@ import { literalCall } from "../examples/returnLiteralCall.js"; import { multiReturnCall } from "../examples/multiReturnCall.js"; import { declareCall } from "../examples/declareCall.js"; import { genOptions, genOptionsEmptyString } from "../examples/optionsCall.js"; -import { lng193BugCall } from "../examples/closureReturnRename.js"; +import { lng193BugCall, lng365BugCall } from "../examples/closureReturnRename.js"; import { closuresCall, multipleClosuresLNG262BugCall, @@ -1232,6 +1232,12 @@ describe("Testing examples", () => { expect(result).toEqual(1 + 42 + (2 + 42) + (3 + 42) + (4 + 42)); }, 20000); + it("closureReturnRename.aqua bug LNG-365", async () => { + const [values, keys] = await lng365BugCall(); + expect(values).toEqual(["one", "two", "three"]); + expect(keys).toEqual(["1", "2", "3"]); + }); + it("closures.aqua", async () => { const closuresResult = await closuresCall(); const res1 = config.externalAddressesRelay2; diff --git a/integration-tests/src/examples/closureReturnRename.ts b/integration-tests/src/examples/closureReturnRename.ts index 60874bdfc..12ede7628 100644 --- a/integration-tests/src/examples/closureReturnRename.ts +++ b/integration-tests/src/examples/closureReturnRename.ts @@ -1,4 +1,4 @@ -import { lng193Bug } from "../compiled/examples/closureReturnRename.js"; +import { lng193Bug, lng365Bug } from "../compiled/examples/closureReturnRename.js"; import { config } from "../config.js"; const relays = config.relays; @@ -6,3 +6,7 @@ const relays = config.relays; export async function lng193BugCall(): Promise { return lng193Bug(relays[4].peerId, relays[5].peerId); } + +export async function lng365BugCall() { + return lng365Bug(); +} diff --git a/model/raw/src/main/scala/aqua/raw/ops/RawTag.scala b/model/raw/src/main/scala/aqua/raw/ops/RawTag.scala index 2227dded9..d447cd9ce 100644 --- a/model/raw/src/main/scala/aqua/raw/ops/RawTag.scala +++ b/model/raw/src/main/scala/aqua/raw/ops/RawTag.scala @@ -306,7 +306,10 @@ case class ClosureTag( override def renameExports(map: Map[String, String]): RawTag = copy(func = func.copy( - name = map.getOrElse(func.name, func.name) + name = map.getOrElse(func.name, func.name), + arrow = func.arrow.copy( + body = func.arrow.body.map(_.renameExports(map)) + ) ) )