tek / splain

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

Attach existential context & alias annotations to type text on demand #113

Closed tribbloid closed 9 months ago

tribbloid commented 9 months ago

Considering the example:

object Test {

      class A {
        class B
        def b: B = new B
      }

      class F[T]

      val a = new A

      def wrongf(a: A)(implicit b: (F[a.type])): Unit = {}

      wrongf(new A)(new F[a.type])
      wrongf(new A)
    }

The original error:

newSource1.scala:14: error: type mismatch;
  Test.F[Test.a.type|a.type]
      wrongf(new A)(new F[a.type])
                    ^
newSource1.scala:15: error: implicit error;
!I b: Test.F[a.type]
      wrongf(new A)
            ^

is good enough if you read the code carefully and memorize the definition of every dependent types (in the function or the object), but it may be difficult for people without a background in dependent type theory. This is why Scala compiler 2.13 builtin diff use the following implementation:

      def baseMessage = {
        ";\n found   : " + found.toLongString + existentialContext(found) + explainAlias(found) +
         "\n required: " + req + existentialContext(req) + explainAlias(req)
      }

Should we optionally do the same?

tribbloid commented 9 months ago

I propose to add the Vtype-detail plugin option which takes an integer:

@tek what do you think?