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

StackProxy does not work #5428

scabug opened this issue Feb 1, 2012 · 4 comments


Copy link

commented Feb 1, 2012

Welcome to Scala version (Java HotSpot(TM) Client VM, Java 1.6.0_26).
Type in expressions to have them evaluated.
Type :help for more information.

scala> import collection.mutable.{Stack,StackProxy}
import collection.mutable.{Stack, StackProxy}

scala> class A extends StackProxy[Int] {def self = Stack[Int]()}
defined class A

scala> val a = new A
a: A = Stack()

scala> a push 3
res0: a.type = Stack()

scala> a push 4
res1: a.type = Stack()

scala> a push 5
res2: a.type = Stack()

scala> a
res3: A = Stack()

scala> a pop
java.util.NoSuchElementException: head of empty list
	at scala.collection.immutable.Nil$.head(List.scala:371)
	at scala.collection.immutable.Nil$.head(List.scala:368)
	at scala.collection.mutable.Stack.pop(Stack.scala:146)
	at scala.collection.mutable.StackProxy$class.pop(StackProxy.scala:80)
	at A.pop(<console>:8)
	at .<init>(<console>:11)
	at .<clinit>(<console>)
	at .<init>(<console>:11)
	at .<clinit>(<console>)
	at $print(<console>)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(
	at java.lang.reflect.Method.invoke(


This comment has been minimized.

Copy link

commented Feb 1, 2012

Imported From:
Reporter: Felix Dietze (man)
Affected Versions: 2.9.1
See #4290


This comment has been minimized.

Copy link

commented Feb 7, 2012

@adriaanm said:
Philipp, could you please take a look or re-assign?


This comment has been minimized.

Copy link

commented Feb 13, 2012

Felix Dietze (man) said:
I had a look in the source, and it seems like the push-method with only one argument is not overwritten. This could maybe fix the issue:

override def push(elem:A): this.type = {self.push(elem); this}

This comment has been minimized.

Copy link

commented May 24, 2012

@axel22 said:
That's not the only issue.
You've defined the self method to instantiate a new StackInt each time it is called. You should either have a val or def should return a stable reference.

@scabug scabug closed this Jan 8, 2013

@scabug scabug added this to the 2.10.0-M3 milestone Apr 7, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
2 participants
You can’t perform that action at this time.