fix(compiler): Bug in renaming [LNG-346] (#1094)

This commit is contained in:
Dima 2024-02-29 12:23:34 +03:00 committed by GitHub
parent 6e9689945d
commit d7fef3db5f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 109 additions and 13 deletions

View File

@ -1,12 +1,48 @@
aqua Job declares *
aqua Main
import someString from "hack"
use timeout, someString from "hack.aqua" as P
export bugLNG346
export timeout
ability Promise:
yield() -> string
func timeout() -> string:
res <- P.timeout()
b = someString()
a = P.someString()
func done_nil() -> string:
<- ""
func done() -> Promise:
<- Promise(yield = done_nil)
ability Compute:
yield() -> string
alias WorkerYield: -> string
alias Yield: WorkerYield -> Promise
func wait_for() -> Yield:
wait = func (cb: -> string) -> Promise:
yield = func () -> string:
e <- cb()
<- e
<- Promise(yield = yield)
<- wait
ability Function:
run(dealId: string) -> string
func simple{Compute}(yield: Yield) -> Function:
deal_run = func () -> string:
c_yield = func () -> string:
<- Compute.yield()
yieeld <- yield(c_yield)
res <- yieeld.yield()
<- res
<- Function(run = deal_run)
func bugLNG346() -> string:
res: *string
yieeld = func () -> string:
res <<- "hello"
<- ""
c = Compute(yield = yieeld)
fn = simple{c}(wait_for())
r <- fn.run("")
<- res!

View File

@ -1,4 +1,4 @@
module DeclareModule declares decl_foo, decl_bar, SuperFoo, DECLARE_CONST, DECLARE_CONST2
aqua DeclareModule declares decl_foo, decl_bar, SuperFoo, DECLARE_CONST, DECLARE_CONST2
export SuperFoo
const DECLARE_CONST = "declare_const"

View File

@ -0,0 +1,48 @@
aqua AbilitiesClosureRename
export bugLNG346
ability Promise:
yield() -> string
func done_nil() -> string:
<- ""
func done() -> Promise:
<- Promise(yield = done_nil)
ability Compute:
yield() -> string
alias WorkerYield: -> string
alias Yield: WorkerYield -> Promise
func wait_for() -> Yield:
wait = func (cb: -> string) -> Promise:
yield = func () -> string:
e <- cb()
<- e
<- Promise(yield = yield)
<- wait
ability Function:
run(dealId: string) -> string
func simple{Compute}(yield: Yield) -> Function:
deal_run = func () -> string:
c_yield = func () -> string:
<- Compute.yield()
yieeld <- yield(c_yield)
res <- yieeld.yield()
<- res
<- Function(run = deal_run)
func bugLNG346() -> string:
res: *string
yieeld = func () -> string:
res <<- "hello"
<- ""
c = Compute(yield = yieeld)
fn = simple{c}(wait_for())
r <- fn.run("")
<- res!

View File

@ -41,6 +41,7 @@ import {
returnSrvAsAbilityCall,
} from "../examples/abilityCall.js";
import { bugLNG314Call, bugLNG338Call } from "../examples/abilityClosureCall.js";
import { bugLNG346Call } from "../examples/abilityClosureRenameCall.js";
import {
nilLengthCall,
nilLiteralCall,
@ -670,6 +671,11 @@ describe("Testing examples", () => {
expect(result).toEqual("job done");
});
it("abilitiesClosureRename.aqua bug LNG-346", async () => {
let result = await bugLNG346Call();
expect(result).toEqual("hello");
});
it("functors.aqua LNG-119 bug", async () => {
let result = await bugLng119Call();
expect(result).toEqual([1]);

View File

@ -0,0 +1,8 @@
import {
bugLNG346
} from "../compiled/examples/abilitiesClosureRename.js";
export async function bugLNG346Call(): Promise<string> {
return await bugLNG346();
}

View File

@ -507,9 +507,7 @@ object ArrowInliner extends Logging {
* are prohibited because they are used inside **this function**.
*/
defineNames <- StateT.liftF(
fn.body.definesVarNames.map(
_ -- argNames -- capturedNames
)
fn.body.definesVarNames
)
defineRenames <- Mangler[S].findAndForbidNames(defineNames)
canonStreamsWithNames <- canonStreamVariables(args)