diff options
author | Grzegorz Kossakowski <grzegorz.kossakowski@gmail.com> | 2013-10-03 02:55:34 -0700 |
---|---|---|
committer | Grzegorz Kossakowski <grzegorz.kossakowski@gmail.com> | 2013-10-03 02:55:34 -0700 |
commit | 33be64d195fd2c92707033af3538a92c4948d8c1 (patch) | |
tree | bb87acf76ccc1930a0886c2cb0c5760336f5c82d /src/compiler | |
parent | 44585a7ad43065e3d22df27cc0d17d1e9370b0f2 (diff) | |
parent | 4595ac665674b25af776d499ae1da61bb297d379 (diff) | |
download | scala-33be64d195fd2c92707033af3538a92c4948d8c1.tar.gz scala-33be64d195fd2c92707033af3538a92c4948d8c1.tar.bz2 scala-33be64d195fd2c92707033af3538a92c4948d8c1.zip |
Merge pull request #2965 from retronym/ticket/7859
SI-7859 Value classes may wrap a non-public member
Diffstat (limited to 'src/compiler')
-rw-r--r-- | src/compiler/scala/tools/nsc/transform/ExtensionMethods.scala | 3 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Typers.scala | 30 |
2 files changed, 22 insertions, 11 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/ExtensionMethods.scala b/src/compiler/scala/tools/nsc/transform/ExtensionMethods.scala index f001964fb4..9e8cbe6c03 100644 --- a/src/compiler/scala/tools/nsc/transform/ExtensionMethods.scala +++ b/src/compiler/scala/tools/nsc/transform/ExtensionMethods.scala @@ -191,6 +191,9 @@ abstract class ExtensionMethods extends Transform with TypingTransformers { checkNonCyclic(currentOwner.pos, Set(), currentOwner) */ extensionDefs(currentOwner.companionModule) = new mutable.ListBuffer[Tree] currentOwner.primaryConstructor.makeNotPrivate(NoSymbol) + // SI-7859 make param accessors accessible so the erasure can generate unbox operations. + val paramAccessors = currentOwner.info.decls.filter(sym => sym.isParamAccessor && sym.isMethod) + paramAccessors.foreach(_.makeNotPrivate(currentOwner)) super.transform(tree) } else if (currentOwner.isStaticOwner) { super.transform(tree) diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index cb070a9843..ecd987b031 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -1356,17 +1356,25 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper unit.error(clazz.pos, "value class may not be a "+ (if (clazz.owner.isTerm) "local class" else "member of another class")) if (!clazz.isPrimitiveValueClass) { - clazz.info.decls.toList.filter(acc => acc.isMethod && acc.isParamAccessor) match { - case List(acc) => - def isUnderlyingAcc(sym: Symbol) = - sym == acc || acc.hasAccessorFlag && sym == acc.accessed - if (acc.accessBoundary(clazz) != rootMirror.RootClass) - unit.error(acc.pos, "value class needs to have a publicly accessible val parameter") - else if (acc.tpe.typeSymbol.isDerivedValueClass) - unit.error(acc.pos, "value class may not wrap another user-defined value class") - checkEphemeral(clazz, body filterNot (stat => isUnderlyingAcc(stat.symbol))) - case x => - unit.error(clazz.pos, "value class needs to have exactly one public val parameter") + clazz.primaryConstructor.paramss match { + case List(List(param)) => + val decls = clazz.info.decls + val paramAccessor = clazz.constrParamAccessors.head + if (paramAccessor.isMutable) + unit.error(paramAccessor.pos, "value class parameter must not be a var") + val accessor = decls.toList.find(x => x.isMethod && x.accessedOrSelf == paramAccessor) + accessor match { + case None => + unit.error(paramAccessor.pos, "value class parameter must be a val and not be private[this]") + case Some(acc) if acc.isProtectedLocal => + unit.error(paramAccessor.pos, "value class parameter must not be protected[this]") + case Some(acc) => + if (acc.tpe.typeSymbol.isDerivedValueClass) + unit.error(acc.pos, "value class may not wrap another user-defined value class") + checkEphemeral(clazz, body filterNot (stat => stat.symbol != null && stat.symbol.accessedOrSelf == paramAccessor)) + } + case _ => + unit.error(clazz.pos, "value class needs to have exactly one val parameter") } } |