fix(compiler): Passed function is not handled correctly [LNG-260] (#940)

* Fix renaming

* Add integration test
This commit is contained in:
InversionSpaces 2023-10-23 13:54:09 +02:00 committed by GitHub
parent 441c012e01
commit c83d69e689
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 45 additions and 5 deletions

View File

@ -1,6 +1,6 @@
module Funcs declares main, A, calc
export main, A, calc, calc2, ifCalc
export main, A, calc, calc2, ifCalc, bugLNG260
service A("a"):
getJ(i: u32) -> u32
@ -37,3 +37,25 @@ func ifCalc() -> u64:
else:
res <<- 2
<- res!0
func cmp(a: i32, b: i32, pred: i8 -> bool) -> bool:
result: ?bool
if a < b:
result <- pred(-1)
else:
if a == b:
result <- pred(0)
else:
result <- pred(1)
<- result!
func gt(a: i32, b: i32) -> bool:
pred = (ord: i8) -> bool:
<- ord > 0
<- cmp(a, b, pred)
func bugLNG260(a: i32, b: i32) -> bool:
<- gt(a, b)

View File

@ -127,7 +127,7 @@ import {
optionSugarCall,
streamSugarCall,
} from "../examples/collectionSugarCall.js";
import { funcsCall } from "../examples/funcsCall.js";
import { funcsCall, bugLNG260Call } from "../examples/funcsCall.js";
import { nestedDataCall } from "../examples/nestedDataCall.js";
import {
mathTest1Call,
@ -727,6 +727,15 @@ describe("Testing examples", () => {
expect(result).toEqual([13, 6, 3, 1]);
}, 7000);
it("funcs.aqua bugLNG260", async () => {
let result1 = await bugLNG260Call(1, 2);
expect(result1).toEqual(false);
let result2 = await bugLNG260Call(4, 3);
expect(result2).toEqual(true);
let result3 = await bugLNG260Call(5, 5);
expect(result3).toEqual(false);
});
// it('closures.aqua LNG-58 bug', async () => {
// let res = await lng58Bug()
// expect(res).toEqual("ok")

View File

@ -4,6 +4,7 @@ import {
calc,
calc2,
ifCalc,
bugLNG260,
} from "../compiled/examples/funcs.js";
export async function funcsCall() {
@ -29,3 +30,7 @@ export async function funcsCall() {
return [res1, res2, res3, res4];
}
export async function bugLNG260Call(a: number, b: number) {
return await bugLNG260(a, b);
}

View File

@ -59,7 +59,10 @@ object ArrowInliner extends Logging {
(res @ VarModel(_, StreamType(_), _), resDesugar)
) if !outsideStreamNames.contains(n) =>
resDesugar.toList -> res
case (cexp @ CallModel.Export(exp, st @ StreamType(_)), (res, resDesugar)) =>
case (
cexp @ CallModel.Export(exp, st @ StreamType(_)),
(res, resDesugar)
) =>
// pass nested function results to a stream
(resDesugar.toList :+ PushToStreamModel(res, cexp).leaf) -> cexp.asVar
case (_, (res, resDesugar)) =>

View File

@ -296,7 +296,7 @@ case class ClosureTag(
copy(
func.copy(arrow =
func.arrow.copy(
ret = func.arrow.ret.map(_.map(f)),
ret = func.arrow.ret.map(_.mapValues(f)),
body = func.arrow.body.map(_.mapValues(f))
)
)

View File

@ -8,6 +8,7 @@ import aqua.parser.expr.func.ClosureExpr
import aqua.parser.lexer.Arg
import aqua.semantics.Prog
import aqua.semantics.rules.names.NamesAlgebra
import cats.Applicative
import cats.data.Chain
import cats.syntax.functor.*
@ -16,7 +17,7 @@ import cats.Monad
class ClosureSem[S[_]](val expr: ClosureExpr[S]) extends AnyVal {
def program[Alg[_]: Monad](implicit
def program[Alg[_]: Monad](using
N: NamesAlgebra[S, Alg]
): Prog[Alg, Raw] =
Prog.after {