fix(compiler): Push to stream in closures [LNG-365] (#1157)

This commit is contained in:
Dima 2024-06-18 20:57:55 +07:00 committed by GitHub
parent 1563f7cdd8
commit 77b7b9b4bd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 93 additions and 17 deletions

View File

@ -1,16 +1,41 @@
aqua StreamMapTest declares *
aqua StreamMapAbilities
export testGetFunc, Srv
export streamMapAbilityTest
service Srv("baaa"):
g() -> string
ability Streams:
stream: *string
map: %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
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()

View File

@ -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()

View File

@ -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;

View File

@ -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<number> {
return lng193Bug(relays[4].peerId, relays[5].peerId);
}
export async function lng365BugCall() {
return lng365Bug();
}

View File

@ -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))
)
)
)