diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2014-01-08 06:32:34 -0800 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2014-01-08 06:32:34 -0800 |
commit | fa62c04904ccb27a3925b6ed9104af6060041756 (patch) | |
tree | f84a330df28450b081b1cf2d28c78cd0f2f8012f | |
parent | ea4a7659f4d9fa1ff9fc8feb5c9f4db732ecb4cf (diff) | |
parent | 5b9966d077b8fa7af95fa95d7782243892e6ccad (diff) | |
download | scala-fa62c04904ccb27a3925b6ed9104af6060041756.tar.gz scala-fa62c04904ccb27a3925b6ed9104af6060041756.tar.bz2 scala-fa62c04904ccb27a3925b6ed9104af6060041756.zip |
Merge pull request #3331 from retronym/ticket/8120
SI-8120 Avoid tree sharing when typechecking patmat anon functions
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Typers.scala | 6 | ||||
-rw-r--r-- | test/files/pos/t8120.scala | 9 |
2 files changed, 14 insertions, 1 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index d628638cce..dbe85f4f5a 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -4240,7 +4240,11 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper } val ids = for (p <- params) yield Ident(p.name) val selector1 = atPos(tree.pos.focusStart) { if (arity == 1) ids.head else gen.mkTuple(ids) } - val body = treeCopy.Match(tree, selector1, cases) + // SI-8120 If we don't duplicate the cases, the original Match node will share trees with ones that + // receive symbols owned by this function. However if, after a silent mode session, we discard + // this Function and try a different approach (e.g. applying a view to the reciever) we end up + // with orphaned symbols which blows up far down the pipeline (or can be detected with -Ycheck:typer). + val body = treeCopy.Match(tree, selector1, (cases map duplicateAndKeepPositions).asInstanceOf[List[CaseDef]]) typed1(atPos(tree.pos) { Function(params, body) }, mode, pt) } } else diff --git a/test/files/pos/t8120.scala b/test/files/pos/t8120.scala new file mode 100644 index 0000000000..e06f38d5db --- /dev/null +++ b/test/files/pos/t8120.scala @@ -0,0 +1,9 @@ +object A { + class C { + def m(a: Nothing): Int = 0 + } + implicit class RichAny(a: Any) { + def m(a: Any): Int = 0 + } + (new C).m({ case (x, y) => x } : Any => Any) +} |