Skip to content

correct superaccessor from abstract override lazy val #3167

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
scabug opened this issue Mar 11, 2010 · 11 comments
Closed

correct superaccessor from abstract override lazy val #3167

scabug opened this issue Mar 11, 2010 · 11 comments
Assignees
Milestone

Comments

@scabug
Copy link

scabug commented Mar 11, 2010

I have a trait defined as

trait Thing { def name: String }

I'm trying to stack it using

val t = new Thing with Thing1 with Thing2

where Thing1 and Thing2 are defined as

trait Thing1 extends Thing { override lazy val name = "One" }
trait Thing2 extends Thing { abstract override lazy val name = super.name }

I'm getting a StackOverflowError when trying to access t.name. This happens with both Scala 2.9.0.Beta1 and the March 9th nightly build.

Welcome to Scala version 2.8.0.r21113-b20100309020141 (Java HotSpot(TM) Server VM, Java 1.6.0_15).
Type in expressions to have them evaluated.
Type :help for more information.

scala> trait Thing { def name: String }
defined trait Thing

scala> trait Thing1 extends Thing { override lazy val name = "One" }
defined trait Thing1

scala> trait Thing2 extends Thing { abstract override lazy val name = super.name }
defined trait Thing2

scala> val t = new Thing with Thing1 with Thing2
t: java.lang.Object with Thing with Thing1 with Thing2 = $$anon$$1@91520

scala> t.name
java.lang.StackOverflowError
	at $$anon$$1.name(<console>:8)
	at $$anon$$1.Thing2$$$$super$$name(<console>:8)
	at Thing2$$class.name(<console>:6)
	at $$anon$$1.name(<console>:8)
	at $$anon$$1.Thing2$$$$super$$name(<console>:8)
	at Thing2$$class.name(<console>:6)
@scabug
Copy link
Author

scabug commented Mar 11, 2010

Imported From: https://issues.scala-lang.org/browse/SI-3167?orig=1
Reporter: Richard Wallace (rwallace)

@scabug
Copy link
Author

scabug commented May 30, 2010

@paulp said:
This is a compiler issue.

@scabug
Copy link
Author

scabug commented Mar 15, 2013

@adriaanm said:
Un-assigning to foster work stealing, as announced in https://groups.google.com/forum/?fromgroups=#!topic/scala-internals/o8WG4plpNkw

@scabug
Copy link
Author

scabug commented Jul 10, 2013

@adriaanm said:
Unassigning and rescheduling to M6 as previous deadline was missed.

@scabug
Copy link
Author

scabug commented Aug 5, 2014

@gkossakowski said:
The 2.11.2 is out so I'm rescheduling the issue for 2.11.3.

@scabug
Copy link
Author

scabug commented Nov 4, 2014

@retronym said:
Updating fix-by version to 2.11.5.

@scabug
Copy link
Author

scabug commented Feb 26, 2015

@adriaanm said:

trait Base { def name: String }
trait OverrideLazy extends Base { override def name = "One" }
trait AbstractOverrideLazy extends Base { abstract override def name = super.name }

class ShouldNotLoop extends Base with OverrideLazy with AbstractOverrideLazy // super.name refers to OverrideLazy's name

/* Decompiled to Java

public interface Base {
    public abstract String name();
}

public interface OverrideLazy extends Base {
    public abstract String name();
}

public interface AbstractOverrideLazy extends Base {
    public abstract String AbstractOverrideLazy$$super$name();
    public abstract String name();
}

public abstract class OverrideLazy$class {
  public static String name(OverrideLazy $this) { return "One"; }
  public static void $init$(OverrideLazy overridelazy) {}
}

public abstract class AbstractOverrideLazy$class { 
  public static String name(AbstractOverrideLazy $this) { return $this.AbstractOverrideLazy$$super$name(); }
  public static void $init$(AbstractOverrideLazy abstractoverridelazy){}
}


import scala.runtime.BoxedUnit;

public class ShouldNotLoop implements OverrideLazy, AbstractOverrideLazy {
    private String name$lzycompute() {
        synchronized(this) {
            if(!bitmap$0) {
                name = AbstractOverrideLazy.class.name(this);
                bitmap$0 = true;
            }
            BoxedUnit _tmp = BoxedUnit.UNIT;
        }
        return name;
    }

    public String name() { return bitmap$0 ? name : name$lzycompute(); }

    public String AbstractOverrideLazy$$super$name() { return name(); }

// when replacing the `lazy val`s by `def`s, we get the correct superaccessor
//    public String AbstractOverrideLazy$$super$name() { return OverrideLazy.class.name(this); }

    public ShouldNotLoop()
    {
        OverrideLazy.class.$init$(this);
        AbstractOverrideLazy.class.$init$(this);
    }

    private final String name;
    private volatile boolean bitmap$0;
}

*/

@scabug
Copy link
Author

scabug commented Sep 6, 2016

Christian Schlichtherle (christian_schlichtherle) said:
C'mon dear Scala Devs, this still applies to Scala 2.11.8. :-(

@scabug
Copy link
Author

scabug commented Sep 6, 2016

@som-snytt said:

Welcome to Scala 2.12.0-M5 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_92).
Type in expressions for evaluation. Or try :help.

scala> :pa
// Entering paste mode (ctrl-D to finish)

trait Thing { def name: String }
trait Thing1 extends Thing { override lazy val name = "One" }
trait Thing2 extends Thing { abstract override lazy val name = super.name }

// Exiting paste mode, now interpreting.

defined trait Thing
defined trait Thing1
defined trait Thing2

scala> val t = new Thing with Thing1 with Thing2
t: Thing with Thing1 with Thing2 = $anon$1@18eec010

scala> t.name
res0: String = One

@scabug
Copy link
Author

scabug commented Sep 6, 2016

Christian Schlichtherle (christian_schlichtherle) said:
Nice, is there any chance this will be ported back to 2.11.9 or so?

@scabug
Copy link
Author

scabug commented Sep 6, 2016

@adriaanm said:
We have no plans to backport this, since this fix is the result of deep internal compiler changes in 2.12 (new trait encoding, new internal representation of vals).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants