diff options
-rw-r--r-- | test/files/neg/structural.check | 19 | ||||
-rw-r--r-- | test/files/neg/structural.scala | 45 |
2 files changed, 64 insertions, 0 deletions
diff --git a/test/files/neg/structural.check b/test/files/neg/structural.check new file mode 100644 index 0000000000..a0342c4d9c --- /dev/null +++ b/test/files/neg/structural.check @@ -0,0 +1,19 @@ +structural.scala:3: error: illegal dependent method type + def f(x: { type D; def m: D }) = x.m + ^ +structural.scala:10: error: Parameter type in structural refinement may not refer to abstract type defined outside that same refinement + def f1[C <: AnyRef](x: AnyRef{ type D <: AnyRef; def m[E >: Null <: AnyRef](x: A): AnyRef; val x: A }) = x.m[Tata](x.x) //fail + ^ +structural.scala:11: error: Parameter type in structural refinement may not refer to abstract type defined outside that same refinement + def f2[C <: AnyRef](x: AnyRef{ type D <: AnyRef; def m[E >: Null <: AnyRef](x: B): AnyRef; val x: B }) = x.m[Tata](x.x) //fail + ^ +structural.scala:12: error: Parameter type in structural refinement may not refer to abstract type defined outside that same refinement + def f3[C <: AnyRef](x: AnyRef{ type D <: AnyRef; def m[E >: Null <: AnyRef](x: C): AnyRef; val x: C }) = x.m[Tata](x.x) //fail + ^ +structural.scala:19: error: illegal dependent method type + def f9[C <: AnyRef](x: AnyRef{ type D <: AnyRef; def m[E >: Null <: AnyRef](x: AnyRef): D }) = x.m[Tata](()) //suceed + ^ +structural.scala:42: error: Parameter type in structural refinement may not refer to abstract type defined outside that same refinement + type Summable[T] = { def +(v : T) : T } + ^ +6 errors found diff --git a/test/files/neg/structural.scala b/test/files/neg/structural.scala new file mode 100644 index 0000000000..cf75de9322 --- /dev/null +++ b/test/files/neg/structural.scala @@ -0,0 +1,45 @@ +object Test extends Application { + + def f(x: { type D; def m: D }) = x.m + + class Tata + + abstract class Toto[A <: AnyRef] { + type B <: AnyRef + + def f1[C <: AnyRef](x: AnyRef{ type D <: AnyRef; def m[E >: Null <: AnyRef](x: A): AnyRef; val x: A }) = x.m[Tata](x.x) //fail + def f2[C <: AnyRef](x: AnyRef{ type D <: AnyRef; def m[E >: Null <: AnyRef](x: B): AnyRef; val x: B }) = x.m[Tata](x.x) //fail + def f3[C <: AnyRef](x: AnyRef{ type D <: AnyRef; def m[E >: Null <: AnyRef](x: C): AnyRef; val x: C }) = x.m[Tata](x.x) //fail + def f4[C <: AnyRef](x: AnyRef{ type D <: AnyRef; def m[E >: Null <: AnyRef](x: D): AnyRef; val x: D }) = x.m[Tata](x.x) //suceed + def f5[C <: AnyRef](x: AnyRef{ type D <: AnyRef; def m[E >: Null <: AnyRef](x: E): AnyRef; val x: Tata }) = x.m[Tata](x.x) //suceed + + def f6[C <: AnyRef](x: AnyRef{ type D <: AnyRef; def m[E >: Null <: AnyRef](x: AnyRef): A }) = x.m[Tata](()) //suceed + def f7[C <: AnyRef](x: AnyRef{ type D <: AnyRef; def m[E >: Null <: AnyRef](x: AnyRef): B }) = x.m[Tata](()) //suceed + def f8[C <: AnyRef](x: AnyRef{ type D <: AnyRef; def m[E >: Null <: AnyRef](x: AnyRef): C }) = x.m[Tata](()) //suceed + def f9[C <: AnyRef](x: AnyRef{ type D <: AnyRef; def m[E >: Null <: AnyRef](x: AnyRef): D }) = x.m[Tata](()) //suceed + def f0[C <: AnyRef](x: AnyRef{ type D <: AnyRef; def m[E >: Null <: AnyRef](x: AnyRef): E }) = x.m[Tata](()) //suceed + + } + + val tata = new Tata + val toto = new Toto[Tata] { + type B = Tata + } + + toto.f1[Tata](new AnyRef{ type D = Tata; def m[E >: Null <: AnyRef](x: Tata): AnyRef = null; val x = tata }) + toto.f2[Tata](new AnyRef{ type D = Tata; def m[E >: Null <: AnyRef](x: Tata): AnyRef = null; val x = tata }) + toto.f3[Tata](new AnyRef{ type D = Tata; def m[E >: Null <: AnyRef](x: Tata): AnyRef = null; val x = tata }) + toto.f4[Tata](new AnyRef{ type D = Tata; def m[E >: Null <: AnyRef](x: D): AnyRef = null; val x = tata }) + toto.f5[Tata](new AnyRef{ type D = Tata; def m[E >: Null <: AnyRef](x: E): AnyRef = null; val x = tata }) + + toto.f6[Tata](new AnyRef{ type D = Tata; def m[E >: Null <: AnyRef](x: AnyRef): Tata = null }) + toto.f7[Tata](new AnyRef{ type D = Tata; def m[E >: Null <: AnyRef](x: AnyRef): Tata = null }) + toto.f8[Tata](new AnyRef{ type D = Tata; def m[E >: Null <: AnyRef](x: AnyRef): Tata = null }) + toto.f9[Tata](new AnyRef{ type D = Tata; def m[E >: Null <: AnyRef](x: AnyRef): D = null }) + toto.f0[Tata](new AnyRef{ type D = Tata; def m[E >: Null <: AnyRef](x: AnyRef): E = null }) + + /* Bug #1246 */ + type Summable[T] = { def +(v : T) : T } + def sum[T <: Summable[T]](xs : List[T]) = xs.reduceLeft[T](_ + _) + +}
\ No newline at end of file |