Can't resolve return type <...>

I’m really enjoying starting to poke at the crystal-lang type system a little more, but have run into something that has me a little stumped. I’m unsure if this is due to me not quite grokking it completely yet, or an underlying issue / bug.

When declaring an abstract method that has a self-referencing outer type, but free inner such as:

module Functor(T)
  abstract def fmap(&block : T -> U) : Functor(U) forall U
end

A compiler warning - Warning: can't resolve return type Functor(U) - is generated. Given this is generic over U, I would expect that for this declaration (where the compiler points to for the warning), but would expect that it would be made concrete based on the types on the block when used.

Before opening up a bug, is there something that I’m missing here?

Welcome!

I think this is a bug. My guess is that the compiler (me) forgot to check U in the free variables when checking the type of Functor(U). Please report it. Thank you!

By the way, I would try to avoid using Haskell typeclasses in Crystal. Things such as Functor, Applicative and Monad exist in Haskell for a reason, but they are not needed in Crystal. It’s fun for playing around though.

1 Like

Awesome. Thanks for the lighting fast reply.

Logged: https://github.com/crystal-lang/crystal/issues/8766.

1 Like