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

structural types should be more relaxed about protected methods #3197

Open
scabug opened this issue Mar 20, 2010 · 3 comments
Open

structural types should be more relaxed about protected methods #3197

scabug opened this issue Mar 20, 2010 · 3 comments

Comments

@scabug
Copy link

scabug commented Mar 20, 2010

scala> def f(x: { def clone(): AnyRef }) = x.clone()           
<console>:5: error: method clone cannot be accessed in AnyRef{def clone(): AnyRef}
       def f(x: { def clone(): AnyRef }) = x.clone()
                                             ^

The problem of course is that the access of clone() will be widened to public in any number of AnyRef subclasses, any of which could legally call the method if it would compile.

I can't figure any way to get this signature in. Type alias doesn't get us any closer despite accepting the declaration of a public method:

scala> type FakeClone = { def clone(): AnyRef }
defined type alias FakeClone

scala> def f(x: FakeClone) = x.clone()         
<console>:6: error: method clone cannot be accessed in FakeClone
       def f(x: FakeClone) = x.clone()
                               ^
@scabug
Copy link
Author

scabug commented Mar 20, 2010

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

@scabug
Copy link
Author

scabug commented Mar 21, 2010

@paulp said:
See also #1352 and #1994, I see. (But I consider this issue distinct.)

@scabug
Copy link
Author

scabug commented Aug 3, 2011

@paulp said:
Here's another related thing to fix.

scala> class A { override def clone(): A = new A  }
defined class A

scala> class C { override def clone(): A = new A  }
defined class C

scala> List(new A, new C)
res0: List[ScalaObject{protected[package lang] def clone(): A}] = List(A@2b619bca, C@153b0106)

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

1 participant