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

protected def this has general access #4128

Closed
scabug opened this issue Jan 3, 2011 · 4 comments
Closed

protected def this has general access #4128

scabug opened this issue Jan 3, 2011 · 4 comments

Comments

@scabug
Copy link

scabug commented Jan 3, 2011

protected secondary constructors have general code access.

object O {
   class Foo(name: String) {
      protected def this() = this("")
      protected def length = name.length
   }

   val foo = new Foo()   // should NOT compile (but does)
   val len = foo.length  // DOES NOT compile
}

=== What is the expected behavior? ===
Protected def this should not be accessible by general code.
The compiler ought to flag an error.

=== What do you see instead? ===
Punt

=== Additional information ===
(for instance, a link to a relevant mailing list discussion)

=== What versions of the following are you using? ===

  • Scala:2.9.0.r23885-b20110103142535
  • Java:1.6.0_22
  • Operating system: Linux
@scabug
Copy link
Author

scabug commented Jan 3, 2011

Imported From: https://issues.scala-lang.org/browse/SI-4128?orig=1
Reporter: Richard Emberson (rmemberson)

@scabug
Copy link
Author

scabug commented Jan 4, 2011

Aaron Novstrup (anovstrup) said:
Also fails in 2.8.0.final and 2.8.1.final, so apparently not a recent regression.

@scabug
Copy link
Author

scabug commented Jan 4, 2011

@paulp said:
Not just secondary constructors by any means. All three of these compile in trunk.

package bip {
  class Foo() {
    protected def this(name: String) = this()
  }

  class Foo2 protected (name: String) { }

  protected class Foo3(name: String) { }
}

package bop {
  import bip._

  object P {
    val foo = new Foo("abc")
    val foo2 = new Foo2("abc")
    val foo3 = new Foo3("abc")
  }
}

In 2.7.7, that's three errors.

bip.scala:15: error: wrong number of arguments for constructor Foo: ()bip.Foo
    val foo = new Foo("abc")
              ^
bip.scala:16: error: constructor Foo2 cannot be accessed in object P
    val foo2 = new Foo2("abc")
               ^
bip.scala:17: error: class Foo3 cannot be accessed in package bip
    val foo3 = new Foo3("abc")
                   ^
three errors found  

In 2.8.0 and 2.8.1, one error.

bip.scala:17: error: class Foo3 cannot be accessed in package bip
    val foo3 = new Foo3("abc")
                   ^
one error found  

@scabug
Copy link
Author

scabug commented Jan 4, 2011

@paulp said:
(In r23891) Protected protected constructors. They have been essentially public
since r19547, which was for #1836 but loosened the noose too much.
Closes #4128, review by odersky.

@scabug scabug closed this as completed May 18, 2011
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

1 participant