Skip to content

Commit 1064422

Browse files
committed
WIP: Tests for new trait encoding,
TODO: bytecode diff in pos/t4957?
1 parent c8f875f commit 1064422

9 files changed

+391
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// derived from test/files/pos/S5.scala
2+
3+
// compile with -uniqid to see a hint of the trouble
4+
trait N {
5+
// the symbol for self does not get rebound when synthesizing members in C
6+
val self: N = ???
7+
val n: self.type = self
8+
}
9+
10+
// uncomment extends clause for another bug
11+
abstract class M /*extends N*/ {
12+
val self: N
13+
val n: self.type
14+
}
15+
16+
class C extends M with N
Lines changed: 304 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,304 @@
1+
// test mixin of getters / setters, and implementing abstract
2+
// methods using @BeanProperty
3+
class C extends T with BeanF {
4+
def foo() {
5+
setF("doch!")
6+
setG(true)
7+
this.getF()
8+
}
9+
}
10+
11+
trait T {
12+
@scala.beans.BeanProperty var f = "nei"
13+
@scala.beans.BooleanBeanProperty var g = false
14+
}
15+
16+
trait BeanF {
17+
def getF(): String
18+
def setF(n: String): Unit
19+
20+
def isG(): Boolean
21+
def setG(nb: Boolean): Unit
22+
}
23+
24+
/*
25+
@scala.beans.BeanProperty private[this] var f: String = "nei";
26+
<accessor> def f: String = T.this.f;
27+
<accessor> def f_=(x$1: String): Unit = T.this.f = x$1;
28+
def setF(x$1: String): Unit = T.this.f = x$1;
29+
@scala.beans.BooleanBeanProperty private[this] var g: Boolean = false;
30+
<accessor> def g: Boolean = T.this.g;
31+
<accessor> def g_=(x$1: Boolean): Unit = T.this.g = x$1;
32+
def setG(x$1: Boolean): Unit = T.this.g = x$1;
33+
def getF(): String = T.this.f;
34+
def isG(): Boolean = T.this.g
35+
*/
36+
37+
38+
trait T { final val bla: Int = 123 }
39+
class C extends T // bla should be final in C
40+
41+
42+
43+
trait T { final val C = "S" }
44+
// there should be a C method in `T$class`!
45+
class C extends T { println(C) }
46+
47+
trait T {
48+
type Res
49+
val x: Res = ???
50+
}
51+
52+
abstract class MiddleMan extends T
53+
54+
class C extends MiddleMan with T
55+
56+
//
57+
58+
abstract class Context extends Aliases with AliasesOverrides
59+
60+
trait Aliases {
61+
val TypeTag = "universe.TypeTag"
62+
}
63+
64+
trait AliasesOverrides extends Aliases { // or self: Aliases =>
65+
override val TypeTag = "the real universe.TypeTag"
66+
}
67+
68+
// TODO: check that this prints the right thing....
69+
70+
////////////
71+
72+
trait B { val y = "a" }
73+
trait T extends B {
74+
val x: y.type = y
75+
}
76+
77+
/////////////
78+
trait Foo { self: Meh =>
79+
def bar(x: String) = x == "a"
80+
private final val meh = bar("a")
81+
}
82+
83+
abstract class Meh extends Foo
84+
/////////////
85+
86+
trait SymbolTable {
87+
def currentRunId: Int
88+
}
89+
90+
trait ReflectSetup extends SymbolTable {
91+
override val currentRunId = 1
92+
}
93+
94+
class G extends SymbolTable with ReflectSetup
95+
96+
trait OneVal { val x: Int = 123 }
97+
// class Conflicting extends OneVal { def x: Int = 1 } // error expected TODO: right message
98+
class OverridingVal extends OneVal { override val x: Int = ??? }
99+
100+
101+
trait VolatileAbort {
102+
@volatile private var abortflag = false
103+
}
104+
105+
class DefaultSignalling extends VolatileAbort
106+
107+
trait V {
108+
// ok
109+
// error: java.lang.IllegalArgumentException: Could not find proxy for val f: Function1 in List(value f, value v, trait V, package <empty>, package <root>) (currentOwner= value <local V$class> )
110+
val v = { val f = (x: Int) => x + 1; f(2) }
111+
112+
// ok
113+
// assertion failed:
114+
// Trying to access the this of another class: tree.symbol = trait V, class symbol = object V$class compilation unit: fields.scala
115+
val developmentVersion =
116+
for {
117+
v <- scalaPropOrNone("maven.version.number")
118+
if v endsWith "-SNAPSHOT"
119+
ov <- scalaPropOrNone("version.number")
120+
} yield ov
121+
122+
def scalaPropOrNone(name: String): Option[String] = ???
123+
}
124+
125+
object O extends V
126+
127+
128+
// done
129+
// test/files/trait-defaults/fields.scala:24: error: double definition:
130+
// def signalDelegate_=(x$1: Signalling): Unit at line 24 and
131+
// def signalDelegate_=(x$1: Signalling): Unit at line 24
132+
// have same type
133+
// class SUB extends IterableSplitter
134+
// ^
135+
// one error found
136+
137+
trait Signalling
138+
139+
trait DelegatedSignalling extends Signalling {
140+
var signalDelegate: Signalling
141+
}
142+
143+
trait IterableSplitter extends DelegatedSignalling {
144+
var signalDelegate: Signalling = ???
145+
}
146+
147+
class SUB extends IterableSplitter
148+
149+
150+
151+
// package <empty> {
152+
// abstract trait OneAbstractVar extends Object {
153+
// <accessor> def OneAbstractVar$_setter_$x_=(x$1: Int): Unit;
154+
// <stable> <accessor> def x(): Int
155+
// };
156+
// class ConcVar extends Object with OneAbstractVar {
157+
// <accessor> def OneAbstractVar$_setter_$x_=(x$1: Int): Unit = ();
158+
// private[this] val x: Int = _;
159+
// override <stable> <accessor> def x(): Int = ConcVar.this.x;
160+
// def <init>(): ConcVar = {
161+
// ConcVar.super.<init>();
162+
// OneAbstractVar$class./*OneAbstractVar$class*/$init$(ConcVar.this);
163+
// ConcVar.this.x = scala.this.Predef.???();
164+
// ()
165+
// }
166+
// };
167+
// abstract trait OneAbstractVar$class extends {
168+
// def /*OneAbstractVar$class*/$init$($this: OneAbstractVar): Unit = {
169+
// $this.OneAbstractVar$_setter_$x_=(123);
170+
// ()
171+
// }
172+
// }
173+
// }
174+
175+
class Nest { val x = println(1)}
176+
177+
package scala
178+
179+
trait OneConcreteVal[T] {
180+
@deprecatedOverriding val x = 1 // : T = ???
181+
@volatile var vy = "a"
182+
println(x)
183+
def foo = x
184+
}
185+
186+
187+
trait OneOtherConcreteVal[T] {
188+
var y: T = ???
189+
}
190+
191+
class C extends OneConcreteVal[Int] with OneOtherConcreteVal[String]
192+
193+
object T extends App {
194+
val c = new C
195+
println(c.x)
196+
println(c.y)
197+
}
198+
/*
199+
old decls for trait trait OneOtherConcreteVal: Scope{
200+
def y(): Object;
201+
def y_=(x$1: Object): Unit
202+
}
203+
new decls for trait trait OneOtherConcreteVal: Scope{
204+
def y(): Object;
205+
def y_=(x$1: Object): Unit;
206+
def $init$(): Unit
207+
}
208+
old decls for trait trait OneConcreteVal: Scope{
209+
val x(): Int
210+
}
211+
new decls for trait trait OneConcreteVal: Scope{
212+
val x(): Int;
213+
def $init$(): Unit;
214+
private[this] def x_=(x$1: Int): Unit
215+
}
216+
old decls for class C: Scope{
217+
def <init>(): C
218+
}
219+
mixing in List(method y, method y_=, value x, method x_=) from List(trait OneOtherConcreteVal, trait OneConcreteVal)
220+
()String
221+
()Object
222+
()String
223+
()Object
224+
(x$1: String)Unit
225+
(x$1: Object)Unit
226+
()Int
227+
()Int
228+
()Int
229+
()Int
230+
(x$1: Int)Unit
231+
(x$1: Int)Unit
232+
new decls for class C: Scope{
233+
def <init>(): C;
234+
def y(): Object;
235+
private[this] var y: Object;
236+
def y_=(x$1: Object): Unit;
237+
val x(): Int;
238+
private[this] val x: Int;
239+
private[this] def x_=(x$1: Int): Unit
240+
}
241+
*/
242+
243+
244+
class Meh {
245+
final val x = 1
246+
def foo = x
247+
}
248+
class CE extends Empty
249+
250+
trait T {
251+
val abs: String
252+
protected val protabs: String
253+
val pub = "public"
254+
protected val prot = "protected"
255+
private val privvy = "private"
256+
private[this] val privateThis = "private[this]"
257+
// TODO:
258+
// final val const = "const"
259+
260+
trait Nested { println(abs + privateThis) }
261+
262+
object NO {
263+
println(abs)
264+
println(pub)
265+
println(prot)
266+
println(protabs)
267+
println(privvy)
268+
println(privateThis)
269+
}
270+
271+
trait NT {
272+
println(abs)
273+
println(pub)
274+
println(prot)
275+
println(protabs)
276+
println(privvy)
277+
println(privateThis)
278+
}
279+
280+
class NC {
281+
println(abs)
282+
println(pub)
283+
println(prot)
284+
println(protabs)
285+
println(privvy)
286+
println(privateThis)
287+
}
288+
}
289+
290+
class C extends AnyRef with T {
291+
println("x")
292+
val abs = "abstract"
293+
println("y")
294+
val protabs = "abstract protected"
295+
final val const = "const"
296+
println("z")
297+
}
298+
299+
object Test extends C {
300+
def main(args: Array[String]): Unit = {
301+
NO
302+
new NT{}
303+
new NC
304+
}}

test/files/trait-defaults/gen.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
rm -rf classes
2+
mkdir -p phases
3+
mkdir -p classes
4+
5+
for p in erasure explicitouter flatten mixin
6+
do for i in *.scala
7+
do mkdir -p classes/$i
8+
scalac -d classes/$i -Xprint:$p $i > phases/$i.$p
9+
done
10+
done
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
trait T {
2+
lazy val laze = {println("a"); 1}
3+
4+
val a = 1
5+
println("")
6+
val b = 2
7+
println(a+b)
8+
}
9+
10+
11+
class C extends T
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Lift {
2+
def foo = {
3+
// this will be captured by the MouseHandler trait,
4+
// which gives rise to a new trait field during LambdaLift
5+
var Clicked = "Clicked"
6+
7+
def bar = Clicked
8+
9+
trait MouseHandler {
10+
def mouseClicked = Clicked + bar
11+
}
12+
13+
class CC extends MouseHandler
14+
15+
// new C {}
16+
(new CC).mouseClicked
17+
}
18+
}
19+
20+
object O extends Lift with App {
21+
println(foo)
22+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
trait NestedObj {
2+
private object O { println("NO") }
3+
}
4+
5+
6+
class C extends NestedObj {
7+
def O = ???
8+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
trait NestedObj {
2+
object O { println("NO") }
3+
}
4+
5+
class C extends NestedObj
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
trait Chars {
2+
private[this] val char2uescapeArray: String = ???
3+
}
4+
5+
object Chars extends Chars

0 commit comments

Comments
 (0)