Skip to content

structural types should be more relaxed about protected methods #3197

@scabug

Description

@scabug
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()
                               ^

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions