Skip to content

Wrong templated types in recursive templated function #1714

Closed
@maxime-petitjean

Description

@maxime-petitjean

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>
 )

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