From a5d40982b485e1e425407e623f5754cc11125379 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Sun, 16 Jul 2017 11:52:29 +0200 Subject: [PATCH] Fix #2871: Recognize more types as structural selections The previous condition was flawed because a type such as { val x: Int } && {} should still be recognized as a structural selection of `x`. --- compiler/src/dotty/tools/dotc/ast/TreeInfo.scala | 4 +--- tests/neg/i2871.scala | 5 +++++ 2 files changed, 6 insertions(+), 3 deletions(-) create mode 100644 tests/neg/i2871.scala diff --git a/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala b/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala index 8bc3b01d4cd8..510dbf2143fc 100644 --- a/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala +++ b/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala @@ -659,10 +659,8 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] => rname == tree.name || hasRefinement(parent) case tp: TypeProxy => hasRefinement(tp.underlying) - case tp: OrType => + case tp: AndOrType => hasRefinement(tp.tp1) || hasRefinement(tp.tp2) - case tp: AndType => - hasRefinement(tp.tp1) && hasRefinement(tp.tp2) case _ => false } diff --git a/tests/neg/i2871.scala b/tests/neg/i2871.scala new file mode 100644 index 000000000000..f8cf81326731 --- /dev/null +++ b/tests/neg/i2871.scala @@ -0,0 +1,5 @@ +class Cont[A0](x0: A0) { type A = A0; val x: A = x0 } +object Test { + val c: { type A; val x: A } & { type A = Int } = new Cont(1) + println(c.x : Int) // error: not an instance of Selectable +} \ No newline at end of file