Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8491473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T22:26:06+00:00 2026-06-10T22:26:06+00:00

I have a simple test macro that uses reify. It causes a StackOverflowError during

  • 0

I have a simple test macro that uses reify. It causes a StackOverflowError during macro expansion.

def test() = macro testimpl

def testimpl(c:Context)():c.Expr[Any] = {
  import c.universe._
  val o = reify { // StackOverflowError here
    object O
    O
  }
  o
}

Why does this happen? Can it somehow be avoided?

EDIT: This is what happens with M6. I just tried it with M7 and now it says

implementation restriction: cannot reify type Object{def (): O.type} (ClassInfoType)

So that answers the why question, but the question still remains whether there is a way to work around this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T22:26:08+00:00Added an answer on June 10, 2026 at 10:26 pm

    Currently the reifier doesn’t know how to reify types that reference things defined inside the block being reified. Hence the error.

    But what does it have to do with your example? Here’s how it works.

    To reify your block of code, the compiler uses def apply[T: AbsTypeTag](mirror: MirrorOf[self.type], treec: TreeCreator): Expr[T] (upd. in 2.10.0-RC1 AbsTypeTag has been renamed to WeakTypeTag) to create an object of type Expr that reifies the expression. However implicit in the contract of Expr is that it also captures the type of the reifee, and that gives rise to the problem.

    Therefore you need a workaround. The simplest one would be to cast O in the last line of the snippet to something reifiable, e.g. to write O.asInstanceOf[Object]. Then you can manually strip off the asInstanceOf part from the result.

    scala> reify { object O; O }
    <console>:26: error: implementation restriction: cannot reify type Object{def <init>(): O.type} (ClassInfoType)
                  reify { object O; O }
                        ^
    
    scala> reify { object O; O.asInstanceOf[Object] }
    res1 @ 2d059fd6: reflect.runtime.universe.Expr[Object] =
    Expr[java.lang.Object]({
      object O extends AnyRef {
        def <init>() = {
          super.<init>();
          ()
        }
      };
      O.asInstanceOf[Object]
    })
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple test application (C# console application) that does an HTTP GET
I have a simple controller test, containing a.o. the following code: context POST :create
I have a simple macro (simplified version below). At the moment it assumes that
I have a simple test app where I have a carousel that will instantiate
I have a strange build problem. I have a simple test program that sends
I have a simple test program that when I run I get: ./hello: error
I have a simple test example that works fine, I set the drag/drop properties
I have a simple test that connects to an internal portal. I have selenium
I have a simple test run of some medium-complexity code that won't terminate, i.e.
I have a simple test bash script which looks like that: #!/bin/bash cmd=rsync -rv

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.