diff options
author | Guillaume Martres <smarter@ubuntu.com> | 2017-03-28 17:36:56 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-28 17:36:56 +0200 |
commit | 30bfbd571419569db08bfc5ccc7edb788679b696 (patch) | |
tree | 3874e842d6982f240404f99a181b92a2d81b2f0d | |
parent | 1fe730493f9c8701d781cb3ba89bf4ce400d0e72 (diff) | |
parent | 6135363f8730421202eeb39494d3720b9124131c (diff) | |
download | dotty-30bfbd571419569db08bfc5ccc7edb788679b696.tar.gz dotty-30bfbd571419569db08bfc5ccc7edb788679b696.tar.bz2 dotty-30bfbd571419569db08bfc5ccc7edb788679b696.zip |
Merge pull request #2127 from dotty-staging/fix/variable-pattern-access
Fix desugaring of variable pattern leaking into API
-rw-r--r-- | compiler/src/dotty/tools/dotc/ast/Desugar.scala | 5 | ||||
-rw-r--r-- | tests/run/variable-pattern-access.check | 7 | ||||
-rw-r--r-- | tests/run/variable-pattern-access.scala | 16 |
3 files changed, 26 insertions, 2 deletions
diff --git a/compiler/src/dotty/tools/dotc/ast/Desugar.scala b/compiler/src/dotty/tools/dotc/ast/Desugar.scala index b5be89440..75c7078a1 100644 --- a/compiler/src/dotty/tools/dotc/ast/Desugar.scala +++ b/compiler/src/dotty/tools/dotc/ast/Desugar.scala @@ -557,7 +557,7 @@ object desugar { * val/var/lazy val p = e ==> val/var/lazy val x_1 = (e: @unchecked) match (case p => (x_1)) * * in case there are zero or more than one variables in pattern - * val/var/lazy p = e ==> private synthetic [lazy] val t$ = (e: @unchecked) match (case p => (x_1, ..., x_N)) + * val/var/lazy p = e ==> private[this] synthetic [lazy] val t$ = (e: @unchecked) match (case p => (x_1, ..., x_N)) * val/var/def x_1 = t$._1 * ... * val/var/def x_N = t$._N @@ -586,7 +586,8 @@ object desugar { derivedValDef(original, named, tpt, matchExpr, mods) case _ => val tmpName = ctx.freshName().toTermName - val patMods = mods & (AccessFlags | Lazy) | Synthetic + val patMods = + mods & Lazy | Synthetic | (if (ctx.owner.isClass) PrivateLocal else EmptyFlags) val firstDef = ValDef(tmpName, TypeTree(), matchExpr) .withPos(pat.pos.union(rhs.pos)).withMods(patMods) diff --git a/tests/run/variable-pattern-access.check b/tests/run/variable-pattern-access.check new file mode 100644 index 000000000..1039f6a25 --- /dev/null +++ b/tests/run/variable-pattern-access.check @@ -0,0 +1,7 @@ +# Fields of A: +private final int A.a$$local +private final int A.b$$local +private final scala.Tuple2 A.$1$ +# Methods of A: +public int A.a() +public int A.b() diff --git a/tests/run/variable-pattern-access.scala b/tests/run/variable-pattern-access.scala new file mode 100644 index 000000000..1d27b3e42 --- /dev/null +++ b/tests/run/variable-pattern-access.scala @@ -0,0 +1,16 @@ +class A { + val (a, b) = (1, 2) +} +object Test { + def printFields(cls: Class[_]) = + println(cls.getDeclaredFields.map(_.toString).sorted.deep.mkString("\n")) + def printMethods(cls: Class[_]) = + println(cls.getDeclaredMethods.map(_.toString).sorted.deep.mkString("\n")) + + def main(args: Array[String]): Unit = { + println("# Fields of A:") + printFields(classOf[A]) + println("# Methods of A:") + printMethods(classOf[A]) + } +} |