milessabin/shapeless — pull request #62 by larsrh (2013-11-04 21:28:08+00:00)
Title: Check superclasses when deriving instances of type classes

Given this ADT:

```scala
sealed trait Shape
case class Circle(radius: Int) extends Shape
case class Rectangle(height: Int, width: Int) extends Shape

// and a type class `Binary` with syntax and setup for automatic derivation
```

This is most likely unintended:

```scala
val encoded = Circle(5).encode
// later ...
val decoded = encoded.decode[Shape]
```

The result of the decoding is not what one would expect, since it uses a completely different instance (`Binary[Circle]` vs `Binary[Shape]`).

There are two ways to avoid that problem:
* type ascriptions (smart constructors, ...)
* don't use syntax, but rather explicit style (`Binary[Shape].encode(...)`)

Neither workaround is satisfactory, because they can't *prevent* the mistake completely.

Hence, introduce a warning in the case that a `C[T]` is about to be created where `T` is a trait or class with a sealed parent.

The warning is only issued for stuff related to `TypeClass`, but not the other code using the macros in `Generic`, and can be disabled by importing `shapeless.TypeClass.ignoreParent`.