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

FSC generating spurious errors in the face of anonymous classes #5489

Closed
scabug opened this issue Feb 16, 2012 · 4 comments
Closed

FSC generating spurious errors in the face of anonymous classes #5489

scabug opened this issue Feb 16, 2012 · 4 comments
Assignees
Milestone

Comments

@scabug
Copy link

scabug commented Feb 16, 2012

package repro

trait HasString {
  def string: String
}

class CausesProblems {
  def problems = (
    if ("don't optimize me away!".length == 0)
      new HasString { def string = "wut" }
    else
      new HasString { def string = "okay" }
  ).string
}

Compiles fine without FSC. Compiles fine with FSC too, the first time. Attempting to recompile it without kicking FSC results in:

    Error:Error:line (3)error: overriding method string in trait HasString of type ()String;
method string in class Object of type ()java.lang.String has incompatible type;
(Note that method string in trait HasString of type ()String is abstract,
and is therefore overridden by concrete method string in class Object of type ()java.lang.String)
trait HasString {
    Error:Error:line (10)error: overriding method string in class Object of type ()java.lang.String;
method string needs `override' modifier
new HasString { def string = "wut" }
    Error:Error:line (12)error: overriding method string in class Object of type ()java.lang.String;
method string needs `override' modifier
new HasString { def string = "okay" }
@scabug
Copy link
Author

scabug commented Feb 16, 2012

Imported From: https://issues.scala-lang.org/browse/SI-5489?orig=1
Reporter: Ryan Hendrickson (ryan.hendrickson_bwater)
Affected Versions: 2.9.1
See #438

@scabug
Copy link
Author

scabug commented Jul 1, 2012

@retronym said (edited on Jul 1, 2012 11:07:50 AM UTC):
(s/string/blerg/g from the original example)

During erasure, the compiler lubs the two branches of the if, and ends up calling:

https://github.com/scala/scala/blob/1d67fe/src/reflect/scala/reflect/internal/Symbols.scala#L1439

// in Type#elimAnonymousClass($anon#10194)

clazz.classBound.asSeenFrom(pre, clazz.owner)


// in Symbol#classBound

this       // anonymous class $anon#10194

val tp = refinedType(info.parents, owner) // Object#1815
val thistp = tp.typeSymbol.thisType       // Object#1815
info.decls // Scope{
           //  def <init>#10195(arg$outer#16869: repro.CausesProblems#7101): $anon#10194;
           //  override def blerg#10196(): String#1899;
           //  val repro$CausesProblems$$anon$$$outer#11591(): repro.CausesProblems#7101;
           //  private[this] val $outer#11592: repro.CausesProblems#7101

// Egads!
addMember(Object#1815, Object#1815, blerg#10196)
addMember(Object#1815, Object#1815, repro$CausesProblems$$anon$$$outer#11591)

I tracked this down by adding this to Scope#enter:

      try {
        if (e.sym.name.containsName("blerg") && this == definitions.ObjectClass.info.decls) {
          println("phase = " + phase)
          println("Entering into: " + System.identityHashCode(this))
          println("System.identityHashCode(definitions.ObjectClass.info.decls): " + System.identityHashCode(definitions.ObjectClass.info.decls))
          println("Containing: " + this.map(_.nameString).mkString(","))
          println("From: " + Thread.currentThread().getStackTrace.take(10).map(_.getMethodName).mkString(" -> "))
          println("definitions.ObjectClass.info.decl(newTermName(\"blerg\")) = " + definitions.ObjectClass.info.decl(newTermName("blerg")))
        }
      } catch {
        case x: Throwable => // ignore
      }

I'm not sure about the right way to avoid this.

@scabug
Copy link
Author

scabug commented Jul 1, 2012

@retronym said:
Here's the advent of addMember within classBound.

#438
scala/scala@d3a71dbd8#L0L641

@scabug
Copy link
Author

scabug commented Jul 1, 2012

@retronym said:
scala/scala#802

@scabug scabug closed this as completed Jul 2, 2012
@scabug scabug added this to the 2.10.0-M4 milestone Apr 7, 2017
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