inko icon indicating copy to clipboard operation
inko copied to clipboard

Type checking fails when iterating over C types

Open yorickpeterse opened this issue 5 months ago • 0 comments

Please describe the bug

Certain code patterns that involve C types, such as iterating over Array[Int32], result in a type checking error such as illustrated by this code example:

class async Main {
  fn async main {
    let a = [10 as Int32]

    a.into_iter.each(fn (a) {})
  }
}

This produces the following compile-time error:

test.inko:5:22 error(invalid-type): expected a value of type 'fn (Int32)', found 'fn (Int32)'

This error persists after adding an explicit type annotation to the a argument.

Briefly poking around the code it seems we hit the following code:

https://github.com/inko-lang/inko/blob/47907c4bce2849a0862d42d6d90569f7547a60a6/types/src/check.rs#L765

Printing the value compared against it seems we're comparing against a type parameter. I'm a bit surprised by that because I figured we'd be comparing against a type placeholder instead. Perhaps we just add a case where it allows the type check if the type parameter doesn't define any requirements, but I'd first like to know why we're comparing against a type parameter in the first place.

Operating system

Fedora

Inko version

main

yorickpeterse avatar Sep 04 '24 23:09 yorickpeterse