Skip to content

Bug with inner classe inheritance. #1806

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
nicolasstucki opened this issue Dec 15, 2016 · 6 comments
Closed

Bug with inner classe inheritance. #1806

nicolasstucki opened this issue Dec 15, 2016 · 6 comments

Comments

@nicolasstucki
Copy link
Contributor

The following code

trait A {
  class Inner
 }  
trait B extends A {
  class Inner extends super.Inner
}

fails to compile with this error:

6 |               class Inner extends super.Inner
  |                                   ^^^^^^^^^^^
  |                            cyclic inheritance: class Inner extends itself

This pattern can be found in scala-scala/src/library/scala/collection/parallel/ParSeqLike.scala with protected trait Accessor[R, Tp] extends super.Accessor[R, Tp].

Even worse, the compiler crashes when compiling

trait A {
  class Inner
 }  
trait B extends A {
  class Inner extends super.Inner
}
@odersky
Copy link
Contributor

odersky commented Dec 15, 2016

That's no longer allowed. You have to rewrite the inner classes to have different names. Look at the inner Ops classes in subclasses of type scala.math.Numeric to see what needs to be done.

@odersky
Copy link
Contributor

odersky commented Dec 15, 2016

I could not reproduce the crash. Did you paste the wrong test? (it's the same as the one before).

@nicolasstucki
Copy link
Contributor Author

Oh yes, the correct tests is

trait A {
  class Inner
}  
trait B extends A {
  class Inner2 extends super.Inner
}

@odersky
Copy link
Contributor

odersky commented Dec 15, 2016

That one also works fine for me (?)

@nicolasstucki
Copy link
Contributor Author

Im getting this in the repl:

scala> trait A {
           class Inner
         }   
defined trait A
scala> trait B extends A {
           class Inner2 extends super.Inner
         }exception while typing [cannot display due to dotty.tools.dotc.core.Denotations$StaleSymbol: stale symbol; method line1$object$$iw$$iw$A$Inner$$$outer#32842 in class Inner, defined in Period(19..32, run = 4), is referred to in run Period(32..32, run = 6), raw string = dotty.tools.dotc.printing.Formatting$StringFormatter@18bf3d14] of class class dotty.tools.dotc.ast.Trees$Apply # 2297
exception while typing [cannot display due to dotty.tools.dotc.core.Denotations$StaleSymbol: stale symbol; method line1$object$$iw$$iw$A$Inner$$$outer#32842 in class Inner, defined in Period(19..32, run = 4), is referred to in run Period(32..32, run = 6), raw string = dotty.tools.dotc.printing.Formatting$StringFormatter@4fb64261] of class class dotty.tools.dotc.ast.Trees$TypeDef # 2318
exception while typing [cannot display due to dotty.tools.dotc.core.Denotations$StaleSymbol: stale symbol; method line1$object$$iw$$iw$A$Inner$$$outer#32842 in class Inner, defined in Period(19..32, run = 4), is referred to in run Period(32..32, run = 6), raw string = dotty.tools.dotc.printing.Formatting$StringFormatter@42607a4f] of class class dotty.tools.dotc.ast.Trees$TypeDef # 2320
exception while typing [cannot display due to dotty.tools.dotc.core.Denotations$StaleSymbol: stale symbol; method line1$object$$iw$$iw$A$Inner$$$outer#32842 in class Inner, defined in Period(19..32, run = 4), is referred to in run Period(32..32, run = 6), raw string = dotty.tools.dotc.printing.Formatting$StringFormatter@782663d3] of class class dotty.tools.dotc.ast.Trees$TypeDef # 2322
exception while typing [cannot display due to dotty.tools.dotc.core.Denotations$StaleSymbol: stale symbol; method line1$object$$iw$$iw$A$Inner$$$outer#32842 in class Inner, defined in Period(19..32, run = 4), is referred to in run Period(32..32, run = 6), raw string = dotty.tools.dotc.printing.Formatting$StringFormatter@1990a65e] of class class dotty.tools.dotc.ast.Trees$TypeDef # 2324
exception while typing [cannot display due to dotty.tools.dotc.core.Denotations$StaleSymbol: stale symbol; method line1$object$$iw$$iw$A$Inner$$$outer#32842 in class Inner, defined in Period(19..32, run = 4), is referred to in run Period(32..32, run = 6), raw string = dotty.tools.dotc.printing.Formatting$StringFormatter@64485a47] of class class dotty.tools.dotc.ast.Trees$TypeDef # 2326
exception while typing [cannot display due to dotty.tools.dotc.core.Denotations$StaleSymbol: stale symbol; method line1$object$$iw$$iw$A$Inner$$$outer#32842 in class Inner, defined in Period(19..32, run = 4), is referred to in run Period(32..32, run = 6), raw string = dotty.tools.dotc.printing.Formatting$StringFormatter@25bbf683] of class class dotty.tools.dotc.ast.Trees$PackageDef # 2327
Exception in thread "main" dotty.tools.dotc.core.Denotations$StaleSymbol: stale symbol; method line1$object$$iw$$iw$A$Inner$$$outer#32842 in class Inner, defined in Period(19..32, run = 4), is referred to in run Period(32..32, run = 6)
	at dotty.tools.dotc.core.Denotations$SingleDenotation.staleSymbolError(Denotations.scala:932)
	at dotty.tools.dotc.core.Denotations$SingleDenotation.bringForward(Denotations.scala:742)
	at dotty.tools.dotc.core.Denotations$SingleDenotation.current(Denotations.scala:786)
	at dotty.tools.dotc.core.Symbols$Symbol.denot(Symbols.scala:387)
	at dotty.tools.dotc.core.Scopes$Scope.denotsNamed(Scopes.scala:119)
	at dotty.tools.dotc.core.SymDenotations$ClassDenotation.membersNamed(SymDenotations.scala:1592)
	at dotty.tools.dotc.core.SymDenotations$ClassDenotation.findMember(SymDenotations.scala:1645)
	at dotty.tools.dotc.core.Types$Type.go$1(Types.scala:445)
	at dotty.tools.dotc.core.Types$Type.findMember(Types.scala:580)
	at dotty.tools.dotc.core.Types$Type.memberExcluding(Types.scala:414)
	at dotty.tools.dotc.core.Types$Type$$anonfun$member$1.apply(Types.scala:398)
	at dotty.tools.dotc.core.Types$Type$$anonfun$member$1.apply(Types.scala:398)
	at dotty.tools.dotc.util.Stats$.track(Stats.scala:35)

@nicolasstucki
Copy link
Contributor Author

It looks like the issue is only in the repl

odersky added a commit to dotty-staging/dotty that referenced this issue Dec 16, 2016
Some outer accessors were defined at phase explicitOuter,
but were entered into the scope of their enclosing class only
at phase explicitOuter + 1. This turned them to stale symbols
when trying to access them at a later run, because at their
initially valid phase they were not found as members of
their owner.
@odersky odersky self-assigned this Dec 16, 2016
DarkDimius added a commit that referenced this issue Dec 16, 2016
Fix #1806: Define outer accessors at the right phase
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

3 participants