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

Traits + clone = boom! #151

Closed
scabug opened this issue Oct 3, 2007 · 7 comments
Closed

Traits + clone = boom! #151

scabug opened this issue Oct 3, 2007 · 7 comments
Assignees
Milestone

Comments

@scabug
Copy link

scabug commented Oct 3, 2007

package test
object Main {
  trait Foo extends Cloneable {
    def copy : Foo = clone.asInstanceOf[Foo]
  }
  def main(args : Array[String]) : Unit = {
    Console.println("hello")
    val foo = new Foo {}
    Console.println(foo.copy)
  }
}

Run it and weep. All protected methods from a class that a trait extends need to be bridged, especially if the class is coming from Java.

@scabug
Copy link
Author

scabug commented Oct 3, 2007

Imported From: https://issues.scala-lang.org/browse/SI-151?orig=1
Reporter: @mcdirmid

@scabug
Copy link
Author

scabug commented Apr 22, 2008

@dragos said:
Fixed in r14773.

@scabug
Copy link
Author

scabug commented Jan 14, 2009

@odersky said:
Milestone 2.7.1 deleted

@scabug
Copy link
Author

scabug commented Oct 20, 2011

Kahli Burke (kahliburke) said:
I didn't mean to open this earlier

@scabug
Copy link
Author

scabug commented Sep 9, 2014

Andrzej Jozwik (ajozwik) said:
Possibly regression in scala 2.10/2.11/2.12
See:
http://stackoverflow.com/a/25738632/651140

// Java API
public interface JavaAPI {
  JustSomeAPISpecificType clone();
}
public enum JustSomeAPISpecificType{
INSTANCE
}
public class Factory {

        public static class JavaApiImpl implements JavaAPI{

                public JustSomeAPISpecificType clone(){
                        return JustSomeAPISpecificType.INSTANCE;
                }
        }

        public static JavaAPI getAPI(){
                return new JavaApiImpl();
        }
}

Test with sbt/scala console:

scala> val api = Factory.getAPI
api: JavaAPI = Factory$JavaApiImpl@57a645

scala> api.clone
<console>:9: error: method clone in class Object cannot be accessed in JavaAPI
 Access to protected method clone not permitted because
 prefix type JavaAPI does not conform to
 object $iw where the access take place
              api.clone

@scabug
Copy link
Author

scabug commented Jan 30, 2017

Yaroslav Nedumov (yarnedumov) said:
Hi,

According to Andrzej Jozwik's last comment this bug is reproducible again (in Scala 2.10-2.12). I didn't test 2.10 and 2.12, but I can confirm it for Scala 2.11.8.
Since it looks like Andrzej forgot to reopen bug, I am doing this.

@SethTisue
Copy link
Member

please open a new ticket, reopening old tickets that regressed messes with milestones and such

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

3 participants