Open mbovel opened 4 weeks ago
I tried to add a notion of "temporary parameter types", that would be used in MethodType
before paramInfos
are properly initialized: https://github.com/mbovel/dotty/tree/mb/21595. That seems hacky, but that's the smallest changset I can think of. What else could we do? Refactor MethodType
more deeply so that it computes parameters one by one? Would you use a mutable sequence for that?
@EugeneFlesselle and @natsukagami noted that we have a similar limitation with default parameters:
-- [E006] Not Found Error: 21595.scala:3:32 ------------------------------------
3 | def foo(elem: Int, bla: Int = elem + 1) = bla
| ^^^^
| Not found: elem
|
| longer explanation available when compiling with `-explain`
A workaround for both is to use multiple parameter lists:
object Test:
def foo(elem: Int)(bla: Int = elem + 1) = bla
class dummy(b: Boolean) extends annotation.StaticAnnotation
object Test:
def foo(elem: Int)(bla: Int @dummy(elem == 0)) = bla
(Note also that I don't have this problem on my qualified types experiments, because I have a custom annotation with a custom representation and its own mapWith
. With these, the method resolution is never re-triggered. I wondering if this could be problematic in some situations.)
I am more and more convinced that the whole approach of letting annotations take arbitrary trees is doomed. We'll never get it to work properly in all cases. We should seriously consider switching to annotations taking types (including constant and singleton types), not trees.
I had a similar issue with integrateRT
in cc.Setup
(for a different reason)!
Originally posted by @smarter in https://github.com/scala/scala3/issues/19957#issuecomment-2305262773