-
Notifications
You must be signed in to change notification settings - Fork 13
Description
In the issue #16 it was discovered that sometimes the presence of a 2nd overloaded method with an extra argument can sometimes "trick" Scala 2 into thinking a correct macro-method is correct.
It was discovered that when you add a 2nd "dummy method" for example:
def defer[T](value: T): ZIO[_, _, _] = macro core.Macro.deferImpl[T]
def defer[T](regex: Something)(value: T): ZIO[_, _, _] = ??? // dummy method
The
Somethingclass can be anything. I tried java.util.Regex which has nothing to do with anything. Note that the 2nd value can also be of type regex and that the 2nd thing does not even need to be a macro.
In order to do this:
val out =
defer {
val i = Ref.make(0).run
while (i.get.run < 3)
i.getAndUpdate(i => i + 1).run
i.get.run
}
The following above code that normally throws a "macro has not been expanded" error will somehow work.
This is shown in the following branch.
https://github.com/zio/zio-direct/tree/crazy-macro-expansion-error
There are other scenarios where "macro has not been expanded" will occur. for example, if you have a macro the wrong number of arguments:
val out =
defer({
val i = Ref.make(0).run
while (i.get.run < 3)
i.getAndUpdate(i => i + 1).run
i.get.run
}, null) // add extra 'null' argument
Need to watch out for potential similar issues and think about mitigations.