tek / splain

better implicit errors for scala
MIT License
370 stars 29 forks source link

Differentiating ambiguous type texts for type diff and type bound evidences #112

Closed tribbloid closed 9 months ago

tribbloid commented 9 months ago

3 canonical examples are:

object Diff {
      def add2(x:Long,y:Long): Long = x + y

      def add[Long](x: List[Long], y: List[Long]): List[Long] =
        if (x.isEmpty || y.isEmpty) Nil
        else add2(x.head, y.head) :: add(x.tail, y.tail)
    }
    object DiffInEq {
      def add2[T](y: T)(
          implicit
          ev: T =:= Long
      ): Long = 1L + ev(y)

      def add[Long](x: List[Long]): List[Long] = {

        add2(x.head)
      }
    }
    object DiffInSubtype {
      def add2[T](y: T)(
          implicit
          ev: T <:< Long
      ): Long = 1L + ev(y)

      def add[Long](x: List[Long]): List[Long] = {

        add2(x.head)
      }
    }

In all 3 cases, the type text Long is ambivalent (in either referring to higher kind argument Long, or type Long). This may cause apparently inhabited types like X <:< X, X =:= X and X|X to be reported as invalid.

tribbloid commented 9 months ago

My intended solution is to introduce new plugin option Vtype-diffs-detail that takes an integer:

@tek what do you think?