Skip to content

Commit faa0a1b

Browse files
committed
Add test
As @smarter has noticed, the original i3638 seems to be a distillation of this larger test.
1 parent 738c172 commit faa0a1b

File tree

2 files changed

+174
-0
lines changed

2 files changed

+174
-0
lines changed

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)