Skip to content
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

Potential non-sensical Scala 2 macro expansion errors #17

Open
deusaquilus opened this issue Dec 15, 2022 · 0 comments
Open

Potential non-sensical Scala 2 macro expansion errors #17

deusaquilus opened this issue Dec 15, 2022 · 0 comments

Comments

@deusaquilus
Copy link
Contributor

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 Something class 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant