Skip to content

enum inside macro impl #9902

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

Closed
rnd4222 opened this issue Sep 28, 2020 · 3 comments
Closed

enum inside macro impl #9902

rnd4222 opened this issue Sep 28, 2020 · 3 comments

Comments

@rnd4222
Copy link

rnd4222 commented Sep 28, 2020

Minimized code

    enum T:
      case N
      case C(i: Int, t: T)
    T.C(1, T.C(2, T.N))

Output

[error]    |  Exception occurred while executing macro expansion.
[error]    |  java.lang.StackOverflowError

Expectation

When this example is defined in a regular code, it works fine.
When used inside of a macro implementation, it causes StackOverflow.
Workaround is to replace case N with case N() or replace enum with a sealed trait hierarchy.

@bishabosha
Copy link
Member

reproduced in REPL with this code:

import quoted._

inline def someMacro: Any = ${ someMacroImpl }

def someMacroImpl(using QuoteContext): Expr[Any] = {
  enum T:
    case N
    case C(i: Int, t: T)
  T.C(1, T.C(2, T.N))
  '{null}
}
scala> someMacro                                                                                                        
1 |someMacro
  |^^^^^^^^^
  |Exception occurred while executing macro expansion.
  |java.lang.StackOverflowError
  |
  | This location contains code that was inlined from rs$line$4:1

@bishabosha
Copy link
Member

this is due to a local enum in a method:

def foo: Any = {
   enum T:
     case N
     case C(i: Int, t: T)
   T.C(1, T.C(2, T.N))
   null
 }

this has an infinite loop in the construction of object T

@bishabosha
Copy link
Member

this is already fixed in #9677

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

No branches or pull requests

2 participants