inet-js icon indicating copy to clipboard operation
inet-js copied to clipboard

Odd type-checking fail with generic function parameters

Open bojidar-bg opened this issue 9 months ago • 0 comments

Reproduction:

// Setup, a generic type and a few helper nodes
type Gen(Element: @Type)
type Normal
node del(
  value!: Normal
  ------
)
node normal(
  ------
  value!: Normal,
)
node passGen(
  valueIn!: Gen('A)
  ------
  valueOut: Gen('A)
)

// As a node, typechecks perfectly:
node testNode(
  paramGen: Gen(Normal),
  paramNormal!: Normal
  ------
  out: Gen(Normal),
)
rule testNode(paramGen, paramNormal!, out) normal(value!) {
  let paramNormal = normal()

  del(paramNormal)
  let variable = passGen(paramGen)

  @connect(variable, out)
}

// As a function, fails to typecheck: (observe that the types and body are the same; the node just needs a few extra wrapper lines)
function testFunction(paramGen: Gen(Normal), paramNormal: Normal): Gen(Normal) {

  del(paramNormal) // <- I fail to unify types -- left: Normal | right: Normal Gen
  let variable = passGen(paramGen)

  return variable
}

Link to playground

bojidar-bg avatar Oct 30 '23 03:10 bojidar-bg