From 4db73388f2d63eb9b57fecfbd0d76203d7a71c18 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Fri, 31 Dec 2010 08:52:36 +0000 Subject: Modified the self-type protected accessor test ... Modified the self-type protected accessor test to avoid unnecessary runtime failures. Closes #4119, review by dragos. --- .../scala/tools/nsc/typechecker/SuperAccessors.scala | 12 ++++++------ test/files/run/bug4119/J.java | 7 +++++++ test/files/run/bug4119/S.scala | 14 ++++++++++++++ 3 files changed, 27 insertions(+), 6 deletions(-) create mode 100644 test/files/run/bug4119/J.java create mode 100644 test/files/run/bug4119/S.scala diff --git a/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala b/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala index c2110f104d..985652deaa 100644 --- a/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala +++ b/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala @@ -434,18 +434,18 @@ abstract class SuperAccessors extends transform.Transform with transform.TypingT && (sym.owner.enclosingPackageClass == packageAccessBoundry(sym)) ) val host = hostForAccessorOf(sym, clazz) - def isSelfType = (host.thisSym != host) && { - if (host.thisSym.tpe.typeSymbol.isJavaDefined) + def isSelfType = !(host.tpe <:< host.typeOfThis) && { + if (host.typeOfThis.typeSymbol.isJavaDefined) restrictionError(pos, unit, - "%s accesses protected %s from self type %s.".format(clazz, sym, host.thisSym.tpe) + "%s accesses protected %s from self type %s.".format(clazz, sym, host.typeOfThis) ) true } def isJavaProtected = host.isTrait && sym.isJavaDefined && { restrictionError(pos, unit, - "%s accesses protected %s inside a concrete trait method. " + - "Add an accessor in a class extending %s to work around this bug." . - format(clazz, sym, sym.enclClass) + """|%s accesses protected %s inside a concrete trait method. + |Add an accessor in a class extending %s as a workaround.""".stripMargin.format( + clazz, sym, sym.enclClass) ) true } diff --git a/test/files/run/bug4119/J.java b/test/files/run/bug4119/J.java new file mode 100644 index 0000000000..ee65d33e22 --- /dev/null +++ b/test/files/run/bug4119/J.java @@ -0,0 +1,7 @@ +package foo.bar; + +public abstract class J { + protected void foo(J j) { + return; + } +} diff --git a/test/files/run/bug4119/S.scala b/test/files/run/bug4119/S.scala new file mode 100644 index 0000000000..d6ae5f1b87 --- /dev/null +++ b/test/files/run/bug4119/S.scala @@ -0,0 +1,14 @@ +class S extends foo.bar.J { + sss => + + val fn = () => { + foo(S.this) + } + fn() +} + +object Test { + def main(args: Array[String]): Unit = { + new S + } +} -- cgit v1.2.3