simulacrum icon indicating copy to clipboard operation
simulacrum copied to clipboard

Does not support constrait on this.type

Open Atry opened this issue 9 years ago • 1 comments

@simulacrum.typeclass trait MyTypeClass[A] extends AnyRef {
  def opWithThisType(a: A)(implicit constrait: this.type <:< Product) = a
} 
/private/tmp/thistype/MyTypeClass.scala:1: type mismatch;
 found   : <:<[Ops.this.type,Product]
 required: <:<[Ops.this.typeClassInstance.type,Product]
@simulacrum.typeclass trait MyTypeClass[A] extends AnyRef {
 ^

Atry avatar Aug 23 '16 09:08 Atry

I found a workaround:

@simulacrum.typeclass trait MyTypeClass[A] extends AnyRef { typeClassInstance =>
  def opWithThisType(a: A)(implicit constrait: typeClassInstance.type <:< Product) = a
}

Note the self type typeClassInstance =>

Atry avatar Aug 23 '16 09:08 Atry