-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Find implicitNotFoundMessage on types #11823
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@@ -0,0 +1,6 @@ | |||
object Foo: | |||
@annotation.implicitNotFound("Oops") | |||
type Bar |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to also add a test with an opaque type
? Are opaque types
just represented as a TypeRef
like transparent types?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes that's the same
Does this work when the type is just a type alias like this? import scala.annotation.implicitNotFound
@implicitNotFound("${A} is not a subtype of ${B}")
type IsSubtypeOf[-A, +B] = A <:< B
object Example {
implicitly[String IsSubtypeOf Int]
} |
No, since the compiler is free to dealias the type before attempting an implicit search. It has to be an abstract type or opaque type. |
Would it be possible to support that? That functionality exists on Scala 2 and can be helpful for library authors to be able to alias existing types and provide more specific error messages associated with an implicit not being found rather than having to create new data types to wrap the existing ones. |
How is this situation handled? trait Foo:
@implicitNotFound("Oops")
type Bar
trait Foo2 extends Foo:
type Bar = Unit
object Foo3 extends Foo2:
summon[Bar] Although |
@julienrf Looks like this falls back to the generic case as well. |
I had a look: it does not look easy to improve on this. It seems the type is dealiased way before we try to compose an error message. |
@odersky Thanks for looking! |
Fixes #11797