[SI-5428] StackProxy does not work Created: 01/Feb/12  Updated: 11/Aug/16  Resolved: 08/Jan/13

Status: CLOSED
Project: Scala Programming Language
Component/s: None
Affects Version/s: Scala 2.9.1
Fix Version/s: Scala 2.10.0-M3

Type: Bug Priority: Major
Reporter: Felix Dietze Assignee: Aleksandar Prokopec
Resolution: Fixed Votes: 0
Labels: None

Linux Mint, Scala 2.9.1

Issue Links:
relates to SI-4290 missing collections methods in Forwar... CLOSED


Welcome to Scala version 2.9.1.final (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(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.call(IMain.scala:704)
	at scala.tools.nsc.interpreter.IMain$Request$$anonfun$14.apply(IMain.scala:920)
	at scala.tools.nsc.interpreter.Line$$anonfun$1.apply$mcV$sp(Line.scala:43)
	at scala.tools.nsc.io.package$$anon$2.run(package.scala:25)
	at java.lang.Thread.run(Thread.java:662)

Comment by Adriaan Moors [ 07/Feb/12 ]

Philipp, could you please take a look or re-assign?

Comment by Felix Dietze [ 13/Feb/12 ]

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}

Comment by Aleksandar Prokopec [ 24/May/12 ]

That's not the only issue.
You've defined the `self` method to instantiate a new Stack[Int]() each time it is called. You should either have a val or `def` should return a stable reference.

Generated at Fri Oct 19 12:01:49 CEST 2018 using JIRA 7.9.1#79001-sha1:60970b42586a2ec2760ed6cfe825b26961e62b9e.