sophiajt / june

MIT License
813 stars 31 forks source link

Unable to explicitly create an instantiation of a generic struct / create generic struct with array #40

Open lefticus opened 3 months ago

lefticus commented 3 months ago

Type inference works, if I have a value to pass to the generic's construction, but that doesn't always make sense if I want to create an empty container, then fill it later.

struct Array<Contained> {
  width: i64
  height: i64
  contents: raw[Contained] 

  fun create_array(width_: i64, height_: i64) -> Array {
    mut array = new Array(width: width_, height: height_, contents: raw[])
    let size = width_ * height_
    unsafe { resize array.contents size }
    return array
  }
}

// works
let data = new Array(2,3,raw[false])

// does not work
// let data = Array<bool>::create_array(10, 12)
lefticus commented 3 months ago

I'm now unable to compile this example and feeling very confused. I was certain it was working a moment ago