scala / bug

Scala 2 bug reports only. Please, no questions — proper bug reports only.
https://scala-lang.org
232 stars 21 forks source link

Compiler Error on constructor visibility problem in extends clause #6216

Closed scabug closed 11 years ago

scabug commented 12 years ago

Compiler throws an error trying to compile the declaration line of a scala subclass of a java super class.

[ant:scalac] java.lang.Error: Unexpected tree in genLoad: DynamicBooleanProperty.super/class scala.reflect.generic.Trees$Super at: source-/Users/gorzell/dev/git/oss/archaius-gorzell/archaius-scala/src/main/scala/com/netflix/config/scala/DynamicBooleanProperty.scala,line-8,offset=105
[ant:scalac]    at scala.tools.nsc.symtab.SymbolTable.abort(SymbolTable.scala:34)
[ant:scalac]    at scala.tools.nsc.backend.icode.GenICode$ICodePhase.scala$tools$nsc$backend$icode$GenICode$ICodePhase$$genLoad(GenICode.scala:1126)
[ant:scalac]    at scala.tools.nsc.backend.icode.GenICode$ICodePhase$$anonfun$genLoadArguments$1.apply(GenICode.scala:1226)
[ant:scalac]    at scala.tools.nsc.backend.icode.GenICode$ICodePhase$$anonfun$genLoadArguments$1.apply(GenICode.scala:1224)
[ant:scalac]    at scala.collection.LinearSeqOptimized$class.foldLeft(LinearSeqOptimized.scala:111)
[ant:scalac]    at scala.collection.immutable.List.foldLeft(List.scala:45)
[ant:scalac]    at scala.tools.nsc.backend.icode.GenICode$ICodePhase.genLoadArguments(GenICode.scala:1224)
[ant:scalac]    at scala.tools.nsc.backend.icode.GenICode$ICodePhase.scala$tools$nsc$backend$icode$GenICode$ICodePhase$$genLoad(GenICode.scala:924)
[ant:scalac]    at scala.tools.nsc.backend.icode.GenICode$ICodePhase.genLoadQualifier(GenICode.scala:1175)
[ant:scalac]    at scala.tools.nsc.backend.icode.GenICode$ICodePhase.scala$tools$nsc$backend$icode$GenICode$ICodePhase$$genLoad(GenICode.scala:921)
[ant:scalac]    at scala.tools.nsc.backend.icode.GenICode$ICodePhase.scala$tools$nsc$backend$icode$GenICode$ICodePhase$$genStat(GenICode.scala:174)
[ant:scalac]    at scala.tools.nsc.backend.icode.GenICode$ICodePhase$$anonfun$genStat$1.apply(GenICode.scala:143)
[ant:scalac]    at scala.tools.nsc.backend.icode.GenICode$ICodePhase$$anonfun$genStat$1.apply(GenICode.scala:143)
[ant:scalac]    at scala.collection.LinearSeqOptimized$class.foldLeft(LinearSeqOptimized.scala:111)
[ant:scalac]    at scala.collection.immutable.List.foldLeft(List.scala:45)
[ant:scalac]    at scala.tools.nsc.backend.icode.GenICode$ICodePhase.genStat(GenICode.scala:143)
[ant:scalac]    at scala.tools.nsc.backend.icode.GenICode$ICodePhase.scala$tools$nsc$backend$icode$GenICode$ICodePhase$$genLoad(GenICode.scala:1052)
[ant:scalac]    at scala.tools.nsc.backend.icode.GenICode$ICodePhase.gen(GenICode.scala:114)
[ant:scalac]    at scala.tools.nsc.backend.icode.GenICode$ICodePhase$$anonfun$gen$1.apply(GenICode.scala:69)
[ant:scalac]    at scala.tools.nsc.backend.icode.GenICode$ICodePhase$$anonfun$gen$1.apply(GenICode.scala:69)
[ant:scalac]    at scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:59)
[ant:scalac]    at scala.collection.immutable.List.foreach(List.scala:45)
[ant:scalac]    at scala.tools.nsc.backend.icode.GenICode$ICodePhase.gen(GenICode.scala:69)
[ant:scalac]    at scala.tools.nsc.backend.icode.GenICode$ICodePhase.gen(GenICode.scala:136)
[ant:scalac]    at scala.tools.nsc.backend.icode.GenICode$ICodePhase.gen(GenICode.scala:88)
[ant:scalac]    at scala.tools.nsc.backend.icode.GenICode$ICodePhase$$anonfun$gen$1.apply(GenICode.scala:69)
[ant:scalac]    at scala.tools.nsc.backend.icode.GenICode$ICodePhase$$anonfun$gen$1.apply(GenICode.scala:69)
[ant:scalac]    at scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:59)
[ant:scalac]    at scala.collection.immutable.List.foreach(List.scala:45)
[ant:scalac]    at scala.tools.nsc.backend.icode.GenICode$ICodePhase.gen(GenICode.scala:69)
[ant:scalac]    at scala.tools.nsc.backend.icode.GenICode$ICodePhase.gen(GenICode.scala:79)
[ant:scalac]    at scala.tools.nsc.backend.icode.GenICode$ICodePhase.gen(GenICode.scala:65)
[ant:scalac]    at scala.tools.nsc.backend.icode.GenICode$ICodePhase.apply(GenICode.scala:61)
[ant:scalac]    at scala.tools.nsc.Global$GlobalPhase.applyPhase(Global.scala:329)
[ant:scalac]    at scala.tools.nsc.Global$GlobalPhase$$anonfun$run$1.apply(Global.scala:297)
[ant:scalac]    at scala.tools.nsc.Global$GlobalPhase$$anonfun$run$1.apply(Global.scala:297)
[ant:scalac]    at scala.collection.Iterator$class.foreach(Iterator.scala:660)
[ant:scalac]    at scala.collection.mutable.ListBuffer$$anon$1.foreach(ListBuffer.scala:316)
[ant:scalac]    at scala.tools.nsc.Global$GlobalPhase.run(Global.scala:297)
[ant:scalac]    at scala.tools.nsc.backend.icode.GenICode$ICodePhase.run(GenICode.scala:54)
[ant:scalac]    at scala.tools.nsc.Global$Run.compileSources(Global.scala:953)
[ant:scalac]    at scala.tools.nsc.Global$Run.compile(Global.scala:1038)
[ant:scalac]    at scala.tools.ant.Scalac.executeInternal(Scalac.scala:629)
[ant:scalac]    at scala.tools.ant.Scalac.execute(Scalac.scala:577)

Java Class

public class DynamicStringProperty extends PropertyWrapper<String> {

    DynamicStringProperty(String propName, String defaultValue) {
        super(propName, defaultValue);
    }

    /**
     * Get the current value from the underlying DynamicProperty
     */
    public String get() {
        return prop.getString(defaultValue);
    }

    @Override
    public String getValue() {
        return get();
    }
}

Scala Class:

class DynamicStringProperty(property: String, defaultVal: String)
  extends com.netflix.config.DynamicStringProperty(property, defaultVal) {

  def apply(): Option[String] = Option(get())
}
scabug commented 12 years ago

Imported From: https://issues.scala-lang.org/browse/SI-6216?orig=1 Reporter: Greg Orzell (gorzell) Affected Versions: 2.9.1, 2.9.2

scabug commented 12 years ago

@magarciaEPFL said: Please provide a self-contained example, otherwise we can't even look at this. The provided Java class depends on DynamicProperty which in turn depends on a load of other stuff.

scabug commented 12 years ago

Greg Orzell (gorzell) said (edited on Aug 14, 2012 10:07:09 PM UTC): fully contained code can be found here: https://github.com/gorzell/archaius/commit/3fd6ae3545201723c47b3faebc370ccda717dd64 I will try to come up with a more limited example, but since I don't know what is causing the failure it could be tough.

scabug commented 12 years ago

Greg Orzell (gorzell) said: I believe that the root cause here was that i was trying to extend a class with a package protected constructor from outside the package, but the compiler just choking doesn't make that very clear.

scabug commented 11 years ago

@jsalvata said: I've hit this without involvement of a Java class -- just scala code:

object Test {
  sealed class Result private(val id: Short, val isFinal: Boolean)
  case class Ok() extends Result(1, true)
}

(I intended "private[Test]" -- easy to get it wrong)

scabug commented 11 years ago

@jsalvata said: I've removed the "java-interop" tag, since my example doesn't (seem to) involve any Java interoperability.

I've changed the summary to what I believe are the common aspects of both reported cases.

scabug commented 11 years ago

@paulp said: In 2.10 your example fails correctly. I expect the other one does as well.

<console>:9: error: constructor Result in class Result cannot be accessed in class Ok
         case class Ok() extends Result(1, true)
                      ^