This is a continuation of a discussion with @eed3si9n on twitter, regarding the case when a developer wants to deliberately cause the compilation to fail early with a custom message:
(Using Scala 2.13 as an example but you all know how to do it in Scala 3)
It can be assumed that âexplicit error message!â should be seen by its user whenever the function summon is called. But in reality, it may be hidden by other messages that are less relevant:
In the last case, the original message was hidden because it caused an ImplicitNotFound error in its parent context. Is it a bad design, given that âexplicit error message!â comprises the most specific information?
Switching to Scala 3 or enabling â-VImplicitsâ wonât make it visible either. I havenât tested the scenario on Scala 3, but to my best knowledge, user-defined compile-time error message wonât be given special treatment over general ImplicitNotFound message.
The only mitigation (more like a circumvention) Iâm aware of is to overwrite the @ImplicitNotFound annotation of the top-level type symbol. This technique is used for error reporting of Lazy in shapeless, and that of Op in singleton-ops, but it may not begithu unreliable (see this bug for an example)
I was trying to implement a bypass in splain plugin, but turns out that the root of this problem is buried much deeper into the compiler than I expected. Please let me know if this is a feature/improvement that worth pursuing.
It would make sense to at least have the option of displaying underlying errors, without printing the whole implicit resolution trace. E.g. with -verbose, or -explain which already exists in Scala 3.
There is one caveat tho, this mechanism will throw the error IMMEDIATELY, disregarding all the low-level assumptions given. E.g. in the following example:
The use case in question should get our compiler to try get2, encounter the inline error, then fallback to get0 of lower priority. And if and only if all fallback options have failed, it will fail with all the trial and error information on the path collected and reported.
But nooooo, once inline error is called it will fail fatally and abort the search.
Specifically, your singleton-ops has the OpIntercept PR hanging for a long time:
Once it is merged youâll inevitably have multiple paths of evaluation, blocking this fallback mechanism wonât be in your favour
+++++++++++++++++++++++++++++++
[Error] /xxx/src/main/scala/com/tribbloids/spike/dotty/InlineError.scala:38:22: No given instance of type com.tribbloids.spike.dotty.InlineError.Indirect1 was found for parameter x of method summon in object Predef.
I found:
[Error] /xxx/src/main/scala/com/tribbloids/spike/dotty/InlineError.scala:39:22: No given instance of type com.tribbloids.spike.dotty.InlineError.Indirect2 was found for parameter x of method summon in object Predef.
I found:
Iâm afraid most of my understanding of Scala compiler (through writing for splain plugin) are obsolete in Dotty, so I certainly hope to have one your master student to propose a plugin or patch