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

2.13.1 scalac StackOverflowError when annotation argument references the annottee #11870

Open
dbarvitsky opened this issue Jan 29, 2020 · 2 comments

Comments

@dbarvitsky
Copy link

@dbarvitsky dbarvitsky commented Jan 29, 2020

Consider the example:

class Invariant(condition: Unit => Boolean) extends scala.annotation.StaticAnnotation
abstract class Demo {
  @Invariant( _ => x.length == 3 )
  def x: String = "foo"
}

This code results in the java.lang.StackOverflowError through scala.reflect.internal.AnnotationInfos$LazyAnnotationInfo.forcedInfo$lzycompute(AnnotationInfos.scala:158) (scalac-SOE-stack.txt has the full stack trace if you need it). As far as I can tell, the stack trace is different from those encountered in #7449, #1632, #1667 and #10421. Increasing the stack -Xss128m just makes the SOE stack trace longer, so it looks like cyclic init.

Some pointers to help narrow the problem.

  1. The annotation argument does not have to be a lambda. The following snippet yields the same SOE:
class Annot(arg: Any) extends scala.annotation.StaticAnnotation
abstract class Demo {
  @Annot(x)
  def x: String = "foo"
}
  1. The following example compiles fine.
class Annot(arg: Any) extends scala.annotation.StaticAnnotation
abstract class Demo {
  @Annot(y)
  def x: String = "foo"
  def y: String = "bar"
}
  1. However, if you put the annotation on the second field as well, there is the SOE again
class Annot(arg: Any) extends scala.annotation.StaticAnnotation
abstract class Demo {
  @Annot(y)
  def x: String = "foo"

 @Annot(x)
  def y: String = "bar"
}
  1. Finally, the code below causes SOE even when the annotations are different.
class Annot1(arg: Any) extends scala.annotation.StaticAnnotation
class Annot2(arg: Any) extends scala.annotation.StaticAnnotation
abstract class Demo {
  @Annot1(y)
  def x: String = "foo"

  @Annot2(x)
  def y: String = "bar"
}

Thank you!

@lrytz lrytz added the annotations label Jan 30, 2020
@lrytz lrytz added this to the Backlog milestone Jan 30, 2020
@hrhino

This comment has been minimized.

Copy link
Member

@hrhino hrhino commented Jan 31, 2020

I'm going to tentatively point the finger at scala/scala#8338 here (without bisecting) because that seems to be the reason we're looking to inspect the annotations of x at all (to see if it's @uncheckedStable).

It's a tricky one: can we perhaps make AnnotationInfos a little bit less lazy (so that we do know their type symbol during annotSig even if we don't know their type nor args)?

@lrytz lrytz added the regression label Feb 3, 2020
@lrytz

This comment has been minimized.

Copy link
Member

@lrytz lrytz commented Feb 3, 2020

I didn't realize this is a regression

@SethTisue SethTisue modified the milestones: Backlog, 2.13.2, 2.13.3 Feb 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.