From 172f3f68200a0bdc6c7f30547f269899cbbdcf98 Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Sat, 26 Jan 2013 08:04:47 +0100 Subject: Revert "SI-6601 Publicise derived value contstructor after pickler" This reverts commit b07228aebe7aa620af45a681ef60d945ffc65665. The remedy was far worse than the disease: % cat sandbox/test.scala class V private (val a: Any) extends AnyVal % RUNNER=scalac scala-hash b07228aebe sandbox/test.scala [info] b07228aebe => /Users/jason/usr/scala-v2.10.0-256-gb07228a % scala-hash b07228aebe [info] b07228aebe => /Users/jason/usr/scala-v2.10.0-256-gb07228a Welcome to Scala version 2.10.1-20130116-230935-b07228aebe (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_27). Type in expressions to have them evaluated. Type :help for more information. scala> def foo(v: V) = v.a == v.a exception when typing v.a().==(v.a())/class scala.reflect.internal.Trees$Apply constructor V in class V cannot be accessed in object $iw in file scala.reflect.internal.Types$TypeError: constructor V in class V cannot be accessed in object $iw --- src/compiler/scala/tools/nsc/transform/ExtensionMethods.scala | 1 + src/compiler/scala/tools/nsc/typechecker/RefChecks.scala | 2 -- test/files/neg/t6601.check | 4 ---- test/files/neg/t6601/AccessPrivateConstructor_2.scala | 3 --- test/files/neg/t6601/PrivateConstructor_1.scala | 1 - 5 files changed, 1 insertion(+), 10 deletions(-) delete mode 100644 test/files/neg/t6601.check delete mode 100644 test/files/neg/t6601/AccessPrivateConstructor_2.scala delete mode 100644 test/files/neg/t6601/PrivateConstructor_1.scala diff --git a/src/compiler/scala/tools/nsc/transform/ExtensionMethods.scala b/src/compiler/scala/tools/nsc/transform/ExtensionMethods.scala index 39e16c3f58..5318524870 100644 --- a/src/compiler/scala/tools/nsc/transform/ExtensionMethods.scala +++ b/src/compiler/scala/tools/nsc/transform/ExtensionMethods.scala @@ -144,6 +144,7 @@ abstract class ExtensionMethods extends Transform with TypingTransformers { wrap over other value classes anyway. checkNonCyclic(currentOwner.pos, Set(), currentOwner) */ extensionDefs(currentOwner.companionModule) = new mutable.ListBuffer[Tree] + currentOwner.primaryConstructor.makeNotPrivate(NoSymbol) super.transform(tree) } else if (currentOwner.isStaticOwner) { super.transform(tree) diff --git a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala index 969bb8aceb..5cea250eec 100644 --- a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala +++ b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala @@ -1686,8 +1686,6 @@ abstract class RefChecks extends InfoTransform with scala.reflect.internal.trans val bridges = addVarargBridges(currentOwner) checkAllOverrides(currentOwner) checkAnyValSubclass(currentOwner) - if (currentOwner.isDerivedValueClass) - currentOwner.primaryConstructor makeNotPrivate NoSymbol // SI-6601, must be done *after* pickler! if (bridges.nonEmpty) deriveTemplate(tree)(_ ::: bridges) else tree case dc@TypeTreeWithDeferredRefCheck() => abort("adapt should have turned dc: TypeTreeWithDeferredRefCheck into tpt: TypeTree, with tpt.original == dc") diff --git a/test/files/neg/t6601.check b/test/files/neg/t6601.check deleted file mode 100644 index 1410e1b11a..0000000000 --- a/test/files/neg/t6601.check +++ /dev/null @@ -1,4 +0,0 @@ -AccessPrivateConstructor_2.scala:2: error: constructor PrivateConstructor in class PrivateConstructor cannot be accessed in class AccessPrivateConstructor - new PrivateConstructor("") // Scalac should forbid accessing to the private constructor! - ^ -one error found diff --git a/test/files/neg/t6601/AccessPrivateConstructor_2.scala b/test/files/neg/t6601/AccessPrivateConstructor_2.scala deleted file mode 100644 index 816bc10d79..0000000000 --- a/test/files/neg/t6601/AccessPrivateConstructor_2.scala +++ /dev/null @@ -1,3 +0,0 @@ -class AccessPrivateConstructor { - new PrivateConstructor("") // Scalac should forbid accessing to the private constructor! -} diff --git a/test/files/neg/t6601/PrivateConstructor_1.scala b/test/files/neg/t6601/PrivateConstructor_1.scala deleted file mode 100644 index f09d7ad068..0000000000 --- a/test/files/neg/t6601/PrivateConstructor_1.scala +++ /dev/null @@ -1 +0,0 @@ -class PrivateConstructor private(val s: String) extends AnyVal -- cgit v1.2.3 From 5a2828c149d3c82c215a34e8586639ffea12a903 Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Sun, 27 Jan 2013 18:48:57 +0100 Subject: A test case to guide the eventual fix for SI-6601. This demonstrates the need for the reversion in the previous commit. --- test/files/pos/t6601/PrivateValueClass_1.scala | 1 + test/files/pos/t6601/UsePrivateValueClass_2.scala | 10 ++++++++++ 2 files changed, 11 insertions(+) create mode 100644 test/files/pos/t6601/PrivateValueClass_1.scala create mode 100644 test/files/pos/t6601/UsePrivateValueClass_2.scala diff --git a/test/files/pos/t6601/PrivateValueClass_1.scala b/test/files/pos/t6601/PrivateValueClass_1.scala new file mode 100644 index 0000000000..85c3687137 --- /dev/null +++ b/test/files/pos/t6601/PrivateValueClass_1.scala @@ -0,0 +1 @@ +class V private (val a: Any) extends AnyVal \ No newline at end of file diff --git a/test/files/pos/t6601/UsePrivateValueClass_2.scala b/test/files/pos/t6601/UsePrivateValueClass_2.scala new file mode 100644 index 0000000000..461b8397b2 --- /dev/null +++ b/test/files/pos/t6601/UsePrivateValueClass_2.scala @@ -0,0 +1,10 @@ +object Test { + // After the first attempt to make seprately compiled value + // classes respect the privacy of constructors, we got: + // + // exception when typing v.a().==(v.a())/class scala.reflect.internal.Trees$Apply + // constructor V in class V cannot be accessed in object Test in file test/files/pos/t6601/UsePrivateValueClass_2.scala + // scala.reflect.internal.Types$TypeError: constructor V in class V cannot be accessed in object Test + def foo(v: V) = v.a == v.a + def bar(v: V) = v == v +} -- cgit v1.2.3