albrow / fo

An experimental language which adds functional programming features to Go.
Other
1.24k stars 34 forks source link

cannot use r (variable of type *(partial)Ring[T]) as *(partial)Ring[T] value in assignment #3

Closed icholy closed 6 years ago

icholy commented 6 years ago

What am I doing wrong here? https://play.folang.org/p/eFfTizZqyFQ

albrow commented 6 years ago

Syntax looks correct to me. This is a bug in the type-checker and I think I already know where to look. Will get to it as soon as I have a chance.

icholy commented 6 years ago

Here's a similar recursive type which panics when I try to compile.

package main

type A[T] struct {
  Next *A[T]
}

func main() {
  var a A[int]
  a.Next = &a
}

edit: ^^ Pretty sure this is what's been killing your playground.

albrow commented 6 years ago

@icholy your first issue is fixed in 9d30a36bb82b8e43789f513810f4d64da50c2170. As I suspected, the problem was in types/predicates.go which defines rules for whether two types are assignable to one another.

After I added a missing type parameter, the playground example compiles 😄

albrow commented 6 years ago

@icholy your second example is actually a separate issue, so I moved it to #15.

albrow commented 6 years ago

@icholy the first half of the issue had to do with declarations failing in the type checker. The second half of the issue occurred when you actually tried to use the recursive generic type (it resulted in a stack overflow error when trying to generate the appropriate concrete type). It is now fixed in 02a4bdb70ec696af52a10d8bc71cb8ad6fa45dd3.

After a few changes, you can now actually use the Ring type in your original playground example :)

icholy commented 6 years ago

Awesome!