X Tutup
Skip to content

Function reference and parameter are resolved in wrong order. #2989

@Changqing-JING

Description

@Changqing-JING

Bug description

Root cause.
When makeCallIndirect, parameters are executed before function address calculation, it leads to parameters overwrite the value of fn.

Steps to reproduce

Code


function logA(x: i32):void {
  trace(`A: ${x}`);
}

function logB(x: i32):void {
  trace(`B: ${x}`);
}

let fn = logA;

function foo(x: i32):i32 {
  fn = logB;
  return x;
}

fn(foo(42));

Expected behavior
In typescript, the output is A: 42
Observed behavior
In assemblyscript, the output is B: 42

AssemblyScript version

v0.28.9

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      X Tutup