File tree Expand file tree Collapse file tree 2 files changed +49
-0
lines changed Expand file tree Collapse file tree 2 files changed +49
-0
lines changed Original file line number Diff line number Diff line change @@ -52,6 +52,7 @@ class Compiler {
52
52
List (new PatternMatcher ,
53
53
new ExplicitOuter ,
54
54
new ExplicitSelf ,
55
+ new CrossCastAnd ,
55
56
new Splitter ),
56
57
List (new VCInlineMethods ,
57
58
new SeqLiterals ,
Original file line number Diff line number Diff line change
1
+ package dotty .tools .dotc .transform
2
+
3
+ import dotty .tools .dotc .ast .tpd
4
+ import dotty .tools .dotc .core .Contexts .Context
5
+ import dotty .tools .dotc .core .Flags
6
+ import dotty .tools .dotc .core .Types .{NoType , Type , AndType }
7
+ import dotty .tools .dotc .transform .TreeTransforms ._
8
+ import tpd ._
9
+
10
+ import scala .collection .mutable .ListBuffer
11
+
12
+
13
+ /**
14
+ * This transform makes sure that all private member selections from
15
+ * AndTypes are performed from the first component of AndType.
16
+ * This is needed for correctness of erasure. See `tests/run/PrivateAnd.scala`
17
+ */
18
+ class CrossCastAnd extends MiniPhaseTransform { thisTransform =>
19
+
20
+ override def phaseName : String = " crossCast"
21
+
22
+ override def transformSelect (tree : tpd.Select )(implicit ctx : Context , info : TransformerInfo ): tpd.Tree = {
23
+ if (tree.symbol.is(Flags .Private )) {
24
+ // all private member selections have a symbol
25
+ tree.qualifier.tpe.widen match {
26
+ case t @ AndType (l, _) =>
27
+
28
+ // find a component of and type that owns the symbol
29
+ def findType (tp : Type ): Type = {
30
+ tp match {
31
+ case AndType (l, r) =>
32
+ findType(l).orElse(findType(r))
33
+ case t =>
34
+ if (t.decl(tree.symbol.name).suchThat(_ == tree.symbol).exists)
35
+ t
36
+ else NoType
37
+ }
38
+ }
39
+
40
+ val tp = findType(t)
41
+ if (l eq tp) tree
42
+ else tree.qualifier.asInstance(AndType (tp, t)).select(tree.symbol)
43
+ case _ => tree
44
+ }
45
+ }
46
+ else tree
47
+ }
48
+ }
You can’t perform that action at this time.
0 commit comments