Skip to content

Type checker does not detect a signature mismatch #2727

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
FriedrichGretz opened this issue Jul 28, 2023 · 0 comments · Fixed by #2728
Closed

Type checker does not detect a signature mismatch #2727

FriedrichGretz opened this issue Jul 28, 2023 · 0 comments · Fixed by #2728
Labels

Comments

@FriedrichGretz
Copy link

Bug description

Consider the source code below. The function expectCallback needs another function as its argument to produce a number. If we use callback this works as expected.

However, if (by mistake) we use a method we'd expect the compiler to detect a signature mismatch because methods implicitly have an extra this parameter. This is not detected. The code below compiles without issues.

Only during runtime we see the expected problem:

RuntimeError: null function or function signature mismatch
    at assembly/index/expectCallback (wasm://wasm/ca122872:wasm-function[50]:0xfee)

Steps to reproduce

function callback(a: i32): i32 {
  return a + 3
}

class C {
  callback(a: i32): i32 {
    return a + 3
  }  
}

function expectCallback(c: ((arg0:i32) => i32)): i32 {
  return c(4)
}

export function fut(): i32 {
  //return expectCallback(callback)
  const cl = new C()
  return expectCallback(cl.callback)
}

AssemblyScript version

0.27.5

Changqing-JING added a commit to Changqing-JING/assemblyscript that referenced this issue Jul 29, 2023
class member function type is assigned to a normal function type
Changqing-JING added a commit to Changqing-JING/assemblyscript that referenced this issue Jul 29, 2023
class member function type is assigned to a normal function type
CountBleck added a commit to CountBleck/assemblyscript that referenced this issue Jul 31, 2023
In most cases, a function type is assignable to another if the target
`this` parameter is a subtype of the original `this` parameter. However,
this check wasn't performed correctly in `Signature#isAssignableTo`.
Also, the reverse is true when checking whether override signatures are
compatible, since the `this` parameter refers to the subclass that's
overriding the parent class's method. At least, that's how I think it
works...

Fixes AssemblyScript#2727.
Closes AssemblyScript#2728.
CountBleck added a commit to CountBleck/assemblyscript that referenced this issue Jul 31, 2023
In most cases, a function type is assignable to another if the target
`this` parameter is a subtype of the original `this` parameter. However,
this check wasn't performed correctly in `Signature#isAssignableTo`.
Also, the reverse is true when checking whether override signatures are
compatible, since the `this` parameter refers to the subclass that's
overriding the parent class's method. At least, that's how I think it
works...

Fixes AssemblyScript#2727.
Closes AssemblyScript#2728.
CountBleck added a commit to CountBleck/assemblyscript that referenced this issue Jul 31, 2023
In most cases, a function type is assignable to another if the target
`this` parameter is a subtype of the original `this` parameter. However,
this check wasn't performed correctly in `Signature#isAssignableTo`.
Also, the reverse is true when checking whether override signatures are
compatible, since the `this` parameter refers to the subclass that's
overriding the parent class's method. At least, that's how I think it
works...

Fixes AssemblyScript#2727.
Closes AssemblyScript#2728.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant