Skip to content

Commit 738cefb

Browse files
authored
Merge pull request #3715 from dotty-staging/fix-#3638
Fix #3638: Fix protected setter generation
2 parents 651fb83 + a3c5f12 commit 738cefb

File tree

5 files changed

+190
-4
lines changed

5 files changed

+190
-4
lines changed

compiler/src/dotty/tools/dotc/transform/PostTyper.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
218218
super.transform(tree1)
219219
}
220220
case tree @ Assign(sel: Select, _) =>
221-
superAcc.transformAssign(super.transform(tree))
221+
super.transform(superAcc.transformAssign(tree))
222222
case Inlined(call, bindings, expansion) =>
223223
// Leave only a call trace consisting of
224224
// - a reference to the top-level class from which the call was inlined,

compiler/src/dotty/tools/dotc/transform/SuperAccessors.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ class SuperAccessors(thisPhase: DenotTransformer) {
8181
.suchThat(_.signature == superInfo.signature).symbol
8282
.orElse {
8383
ctx.debuglog(s"add super acc ${sym.showLocated} to $clazz")
84-
val deferredOrPrivate = if (clazz is Trait) Deferred else Private
84+
val maybeDeferred = if (clazz is Trait) Deferred else EmptyFlags
8585
val acc = ctx.newSymbol(
86-
clazz, superName, Artifact | Method | deferredOrPrivate,
86+
clazz, superName, Artifact | Method | maybeDeferred,
8787
superInfo, coord = accPos).enteredAfter(thisPhase)
8888
// Diagnostic for SI-7091
8989
if (!accDefs.contains(clazz))
@@ -271,7 +271,7 @@ class SuperAccessors(thisPhase: DenotTransformer) {
271271
val accPos = tree.pos.focus
272272
val protectedAccessor = clazz.info.decl(accName).symbol orElse {
273273
val newAcc = ctx.newSymbol(
274-
clazz, accName, Artifact, accType, coord = accPos).enteredAfter(thisPhase)
274+
clazz, accName, Artifact | Method, accType, coord = accPos).enteredAfter(thisPhase)
275275
val code = DefDef(newAcc, vrefss => {
276276
val (receiver :: value :: Nil) :: Nil = vrefss
277277
Assign(receiver.select(field), value).withPos(accPos)

tests/pos/i3638.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package p {
2+
package a {
3+
class JavaInteraction(arr: Array[Char])
4+
extends java.io.CharArrayReader(arr) {
5+
class Inner {
6+
{
7+
count = count
8+
}
9+
}
10+
}
11+
}
12+
}

tests/run/protectedacc.check

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
10
2+
meth1(1) = 2
3+
meth1(1.0) = 2.0
4+
meth2(1)(1) = prefix: 0
5+
meth2(1)(1) = prefix: 0
6+
meth3 = class [I
7+
100 = 100
8+
id(1) = 1
9+
id('a') = a
10+
count before: 3
11+
count after: 4
12+
10
13+
meth1(1) = 2
14+
meth2(1)(1) = 10
15+
100 = 100

tests/run/protectedacc.scala

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
//############################################################################
2+
// Test Java interaction with scala inner classes
3+
//############################################################################
4+
5+
import java.io.{BufferedReader, File, FileWriter, InputStreamReader}
6+
7+
/** The entry point of this test. It has to come first,
8+
* before the package declarations. The parser wouldn't want it
9+
* any other way.
10+
*/
11+
object Test {
12+
def main(args: Array[String]): Unit = {
13+
val b = new p.b.B;
14+
val c = new b.C;
15+
c.m
16+
17+
val ji = new p.b.JavaInteraction(Array('a', 'b', 'c'));
18+
(new ji.Inner).m;
19+
20+
(new p.b.OuterObj.Inner).m
21+
}
22+
}
23+
24+
package p {
25+
package a {
26+
27+
class A {
28+
protected val x = 10;
29+
30+
protected def meth1(x: Int) = x + 1;
31+
protected def meth1(x: Double) = x + 1
32+
protected def meth2(x: Int)(y: String) = y + (x - 1);
33+
protected def meth3 = Array(1, 2)
34+
35+
protected def f[a](x: a) = x
36+
37+
def getA: this.type = this;
38+
}
39+
40+
/** Test type members */
41+
trait HighlighterXXX {
42+
type Node;
43+
protected def highlight(node : Node) : Unit;
44+
}
45+
46+
/** Test type parameters */
47+
abstract class PolyA[a] {
48+
protected def m(x: a): Unit;
49+
50+
class B {
51+
52+
trait Node {
53+
def s: String = "";
54+
}
55+
protected def tie(x: Node): Unit = { x.s; () }
56+
}
57+
}
58+
59+
/** bug 853, longer path members */
60+
class Global {
61+
abstract class Tree;
62+
}
63+
64+
trait HasNSC {
65+
trait GlobalExt extends Global;
66+
val global : GlobalExt;
67+
import global._;
68+
protected def doTyped(tree : Tree): Tree = tree;
69+
def mkTree : Tree;
70+
doTyped(mkTree);
71+
}
72+
}
73+
74+
package b {
75+
import a._;
76+
77+
/** Test interaction with Scala inherited methods and currying. */
78+
class B extends A {
79+
class C {
80+
def m = {
81+
Console.println(x);
82+
Console.println("meth1(1) = " + meth1(1));
83+
Console.println("meth1(1.0) = " + meth1(1.0));
84+
// test accesses from closures
85+
for (x <- 1 until 3)
86+
Console.println("meth2(1)(1) = " + meth2(1)("prefix: "));
87+
88+
Console.println("meth3 = " + meth3.getClass);
89+
90+
val inc = meth2(1)_;
91+
Console.println("100 = " + inc("10"));
92+
93+
Console.println("id(1) = " + f(1))
94+
Console.println("id('a') = " + f("a"))
95+
96+
getA.x;
97+
}
98+
}
99+
}
100+
101+
/** Test interaction with Java inherited protected fields. */
102+
class JavaInteraction(arr: Array[Char]) extends java.io.CharArrayReader(arr) {
103+
class Inner {
104+
def m = {
105+
Console.println("count before: " + count);
106+
count = count + 1;
107+
Console.println("count after: " + count);
108+
}
109+
}
110+
}
111+
112+
/** Test interaction when outer is an object. */
113+
object OuterObj extends p.a.A {
114+
class Inner {
115+
def m = {
116+
Console.println(x);
117+
Console.println("meth1(1) = " + meth1(1));
118+
Console.println("meth2(1)(1) = " + meth2(1)("1"));
119+
120+
val inc = meth2(1)_;
121+
Console.println("100 = " + inc("10"));
122+
123+
getA.x;
124+
}
125+
}
126+
}
127+
128+
trait ScalaAutoEditXXX extends HighlighterXXX {
129+
trait NodeImpl {
130+
def self : Node;
131+
highlight(self);
132+
}
133+
}
134+
135+
abstract class X[T] extends PolyA[T] {
136+
137+
trait Inner extends B {
138+
def self: T;
139+
def self2: Node;
140+
def getB: Inner;
141+
142+
m(self)
143+
144+
trait InnerInner {
145+
val g = getB
146+
g.tie(self2.asInstanceOf[g.Node])
147+
}
148+
}
149+
}
150+
151+
trait ScalaTyperXXX extends HasNSC {
152+
val global : GlobalExt;
153+
import global._;
154+
trait XXX {
155+
def foo(tree : Tree) = doTyped(tree);
156+
}
157+
}
158+
}
159+
}

0 commit comments

Comments
 (0)