Skip to content

Wrong templated types in recursive templated function #1714

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
maxime-petitjean opened this issue Mar 5, 2021 · 1 comment · Fixed by #1762
Closed

Wrong templated types in recursive templated function #1714

maxime-petitjean opened this issue Mar 5, 2021 · 1 comment · Fixed by #1762
Labels

Comments

@maxime-petitjean
Copy link

When calling recursively a templated function, types seems to be wrong.

Steps to reproduce

Compile the following code:

function foo<T1,T2>(): string {
  if(isInteger<T2>()){
    return foo<T2, T1>();
  }

  return nameof<T1>();
}

export function test(): string {
  return foo<f64, i32>();
}

Expected behavior

Function test() should return "i32".

But this code generate an unexpected infinite loop because of recursive call with wrong types:

(func $module/foo<i32,i32> (result i32)
  i32.const 1
  drop
  call $module/foo<i32,i32>
  return
 )
 (func $module/foo<f64,i32> (result i32)
  i32.const 1
  drop
  call $module/foo<i32,i32> ;; Should be `call $module/foo<i32,f64>`
  return
 )
 (func $module/test (result i32)
  call $module/foo<f64,i32>
 )
@MaxGraey MaxGraey added the bug label Mar 5, 2021
@maxime-petitjean
Copy link
Author

I had the same problem without a recursive call. It seems to be a conflict with template names!

function isSameSize<T, U>(): boolean {
  return sizeof<T>() == sizeof<U>();
}

function isSameSize2<T2, U>(): boolean {
  return sizeof<T2>() == sizeof<U>();
}

function foo<T, U>(): boolean {
  return isSameSize<U, T>() == isSameSize2<U, T>();
}

export function test(): boolean {
  return foo<i32, i64>();
}

Function foo generate:

 (func $module/foo<i32,i64> (result i32)
  call $module/isSameSize<i64,i64> ;; KO with same name (T in foo and T in isSameSize)
  call $module/isSameSize2<i64,i32> ;; OK when renaming T to T2 in isSameSize2
  i32.eq
 )

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.

2 participants