From 394cc426c1ff1da53146679b4e2995ece52a133e Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Fri, 21 Dec 2012 12:39:02 -0800 Subject: Fix and simplify typedTypeConstructor. Investigating the useful output of devWarning (-Xdev people, it's good for you) led back to this comment: "normalize to get rid of type aliases" You may know that this is not all the normalizing does. Normalizing also turns TypeRefs with unapplied arguments (type constructors) into PolyTypes. That means that when typedParentType would call typedTypeConstructor it would find its parent had morphed into a PolyType. Not that it noticed; it would blithely continue and unwittingly discard the type arguments by way of appliedType (which smoothly logged the incident, thank you appliedType.) The simplification of typedTypeConstructor: There was a whole complicated special treatment of AnyRef here which appears to have become unnecessary. Removed special treatment and lit a candle for regularity. Updated lots of tests regarding newly not-so-special AnyRef. --- test/files/jvm/annotations.check | 3 - test/files/neg/override-object-no.check | 4 +- test/files/neg/t2078.check | 2 +- test/files/neg/t2336.check | 2 +- test/files/neg/t3691.check | 2 +- test/files/neg/t4877.check | 6 +- test/files/neg/t5060.check | 4 +- test/files/neg/t5063.check | 2 +- test/files/neg/t6436.check | 4 +- test/files/neg/t6436b.check | 4 +- test/files/neg/t963.check | 2 +- test/files/run/existentials-in-compiler.check | 104 ++++++++++----------- test/files/run/existentials3-new.check | 4 +- test/files/run/macro-declared-in-trait.check | 2 +- test/files/run/reflection-equality.check | 2 +- test/files/run/repl-colon-type.check | 8 +- test/files/run/repl-parens.check | 2 +- test/files/run/t4172.check | 2 +- test/files/run/t5256a.check | 2 +- test/files/run/t5256b.check | 2 +- test/files/run/t5256d.check | 2 +- test/files/run/t5256e.check | 2 +- test/files/run/t5256f.check | 4 +- test/files/scalap/abstractClass/result.test | 2 +- test/files/scalap/abstractMethod/result.test | 2 +- test/files/scalap/cbnParam/result.test | 2 +- test/files/scalap/classPrivate/result.test | 4 +- test/files/scalap/classWithExistential/result.test | 2 +- .../scalap/classWithSelfAnnotation/result.test | 2 +- test/files/scalap/covariantParam/result.test | 2 +- test/files/scalap/defaultParameter/result.test | 4 +- test/files/scalap/implicitParam/result.test | 2 +- test/files/scalap/packageObject/result.test | 2 +- test/files/scalap/paramClauses/result.test | 2 +- test/files/scalap/paramNames/result.test | 2 +- test/files/scalap/sequenceParam/result.test | 2 +- test/files/scalap/simpleClass/result.test | 2 +- test/files/scalap/traitObject/result.test | 4 +- test/files/scalap/typeAnnotations/result.test | 2 +- test/files/scalap/valAndVar/result.test | 2 +- test/files/scalap/wildcardType/result.test | 2 +- 41 files changed, 105 insertions(+), 108 deletions(-) (limited to 'test/files') diff --git a/test/files/jvm/annotations.check b/test/files/jvm/annotations.check index e307f8930d..8a4d58d56c 100644 --- a/test/files/jvm/annotations.check +++ b/test/files/jvm/annotations.check @@ -28,9 +28,6 @@ public Test4$Foo8(int) @test.SourceAnnotation(mails={bill.gates@bloodsuckers.com}, value=http://eppli.com) private int Test4$Foo9.z -@test.SourceAnnotation(mails={bill.gates@bloodsuckers.com}, value=http://eppli.com) -public int Test4$Foo9.getZ() - @test.SourceAnnotation(mails={bill.gates@bloodsuckers.com}, value=http://apple.com) public int Test4$Foo9.x() diff --git a/test/files/neg/override-object-no.check b/test/files/neg/override-object-no.check index 52bad2b937..9cfda80fc3 100644 --- a/test/files/neg/override-object-no.check +++ b/test/files/neg/override-object-no.check @@ -6,8 +6,8 @@ an overriding object must conform to the overridden object's class bound; ^ override-object-no.scala:21: error: overriding object Bar in trait Quux1 with object Bar in trait Quux2: an overriding object must conform to the overridden object's class bound; - found : Object{def g: String} - required: Object{def g: Int} + found : AnyRef{def g: String} + required: AnyRef{def g: Int} trait Quux2 extends Quux1 { override object Bar { def g = "abc" } } // err ^ override-object-no.scala:25: error: overriding object Bar in trait Quux3; diff --git a/test/files/neg/t2078.check b/test/files/neg/t2078.check index 3cdaa7d27a..00bb323a0b 100644 --- a/test/files/neg/t2078.check +++ b/test/files/neg/t2078.check @@ -1,4 +1,4 @@ -t2078.scala:2: error: contravariant type S occurs in covariant position in type => Object{val x: S} of value f +t2078.scala:2: error: contravariant type S occurs in covariant position in type => AnyRef{val x: S} of value f val f = new { val x = y } ^ one error found diff --git a/test/files/neg/t2336.check b/test/files/neg/t2336.check index 983717469c..28acd4d179 100644 --- a/test/files/neg/t2336.check +++ b/test/files/neg/t2336.check @@ -1,4 +1,4 @@ -t2336.scala:6: error: type Foo[Int] is not a stable prefix +t2336.scala:6: error: Foo[Int] is not a legal prefix for a constructor new Foo[Int]#Bar(0) ^ one error found diff --git a/test/files/neg/t3691.check b/test/files/neg/t3691.check index bdf6c268b2..6a7e13049a 100644 --- a/test/files/neg/t3691.check +++ b/test/files/neg/t3691.check @@ -9,7 +9,7 @@ t3691.scala:5: error: type mismatch; val c = (new A[String]{}): { type A } // not ok ^ t3691.scala:7: error: type mismatch; - found : Object{type A = String} + found : AnyRef{type A = String} required: AnyRef{type A[X]} val x = (new { type A = String }): { type A[X] } // not ok ^ diff --git a/test/files/neg/t4877.check b/test/files/neg/t4877.check index a4b1e6a50d..5a2413ca8b 100644 --- a/test/files/neg/t4877.check +++ b/test/files/neg/t4877.check @@ -1,10 +1,10 @@ t4877.scala:4: error: type mismatch; - found : Object{def bar: Int} + found : AnyRef{def bar: Int} required: AnyRef{def bar: String} def foo: AnyRef { def bar: String } = new AnyRef { def bar = 42 } ^ t4877.scala:6: error: type mismatch; - found : Object{def bar(x: Int): String} + found : AnyRef{def bar(x: Int): String} required: AnyRef{def bar(x: Int): Int} def foo3: AnyRef { def bar(x: Int): Int } = new AnyRef { def bar(x: Int) = "abc" } ^ @@ -14,7 +14,7 @@ t4877.scala:7: error: type mismatch; def foo4: C { def bar(x: Int): Int ; def quux(x: Int): Int } = new C { def bar(x: Int) = 5 } ^ t4877.scala:17: error: type mismatch; - found : Object{type Mom = String; def bar(x: Int): Int; def bippy(): List[Int]} + found : AnyRef{type Mom = String; def bar(x: Int): Int; def bippy(): List[Int]} required: B.this.Bippy (which expands to) AnyRef{type Mom; def bar(x: Int): this.Mom; def bippy(): List[this.Mom]} val x: Bippy = new AnyRef { diff --git a/test/files/neg/t5060.check b/test/files/neg/t5060.check index e71f30ccdb..09b2d9a4b1 100644 --- a/test/files/neg/t5060.check +++ b/test/files/neg/t5060.check @@ -1,7 +1,7 @@ -t5060.scala:2: error: covariant type T occurs in contravariant position in type => Object{def contains(x: T): Unit} of value foo0 +t5060.scala:2: error: covariant type T occurs in contravariant position in type => AnyRef{def contains(x: T): Unit} of value foo0 val foo0 = { ^ -t5060.scala:6: error: covariant type T occurs in contravariant position in type => Object{def contains(x: T): Unit} of method foo1 +t5060.scala:6: error: covariant type T occurs in contravariant position in type => AnyRef{def contains(x: T): Unit} of method foo1 def foo1 = { ^ two errors found diff --git a/test/files/neg/t5063.check b/test/files/neg/t5063.check index 84690d0a1d..c6e553c1b5 100644 --- a/test/files/neg/t5063.check +++ b/test/files/neg/t5063.check @@ -1,4 +1,4 @@ -t5063.scala:2: error: value + is not a member of Object +t5063.scala:2: error: value + is not a member of AnyRef super.+("") ^ one error found diff --git a/test/files/neg/t6436.check b/test/files/neg/t6436.check index ecb28f9100..5cee6fb558 100644 --- a/test/files/neg/t6436.check +++ b/test/files/neg/t6436.check @@ -2,8 +2,8 @@ t6436.scala:8: error: type mismatch; found : StringContext required: ?{def q: ?} Note that implicit conversions are not applicable because they are ambiguous: - both method foo1 in object quasiquotes of type (ctx: StringContext)Object{def q: Nothing} - and method foo2 in object quasiquotes of type (ctx: StringContext)Object{def q: Nothing} + both method foo1 in object quasiquotes of type (ctx: StringContext)AnyRef{def q: Nothing} + and method foo2 in object quasiquotes of type (ctx: StringContext)AnyRef{def q: Nothing} are possible conversion functions from StringContext to ?{def q: ?} println(q"a") ^ diff --git a/test/files/neg/t6436b.check b/test/files/neg/t6436b.check index b3c2d73739..21ab972b79 100644 --- a/test/files/neg/t6436b.check +++ b/test/files/neg/t6436b.check @@ -2,8 +2,8 @@ t6436b.scala:8: error: type mismatch; found : StringContext required: ?{def q: ?} Note that implicit conversions are not applicable because they are ambiguous: - both method foo1 in object quasiquotes of type (ctx: StringContext)Object{def q: Nothing} - and method foo2 in object quasiquotes of type (ctx: StringContext)Object{def q: Nothing} + both method foo1 in object quasiquotes of type (ctx: StringContext)AnyRef{def q: Nothing} + and method foo2 in object quasiquotes of type (ctx: StringContext)AnyRef{def q: Nothing} are possible conversion functions from StringContext to ?{def q: ?} println(StringContext("a").q()) ^ diff --git a/test/files/neg/t963.check b/test/files/neg/t963.check index 1f2d0687b3..4dc202c7bd 100644 --- a/test/files/neg/t963.check +++ b/test/files/neg/t963.check @@ -5,7 +5,7 @@ t963.scala:17: error: stable identifier required, but Test.this.y4.x found. val w4 : y4.x.type = y4.x ^ t963.scala:10: error: type mismatch; - found : Object{def x: Integer} + found : AnyRef{def x: Integer} required: AnyRef{val x: Integer} val y2 : { val x : java.lang.Integer } = new { def x = new java.lang.Integer(r.nextInt) } ^ diff --git a/test/files/run/existentials-in-compiler.check b/test/files/run/existentials-in-compiler.check index 4df4b0ca96..0d7a9298b4 100644 --- a/test/files/run/existentials-in-compiler.check +++ b/test/files/run/existentials-in-compiler.check @@ -1,156 +1,156 @@ -abstract trait Bippy[A <: AnyRef, B] extends Object +abstract trait Bippy[A <: AnyRef, B] extends AnyRef extest.Bippy[_ <: AnyRef, _] -abstract trait BippyBud[A <: AnyRef, B, C <: List[A]] extends Object +abstract trait BippyBud[A <: AnyRef, B, C <: List[A]] extends AnyRef extest.BippyBud[A,B,C] forSome { A <: AnyRef; B; C <: List[A] } -abstract trait BippyLike[A <: AnyRef, B <: List[A], This <: extest.BippyLike[A,B,This] with extest.Bippy[A,B]] extends Object +abstract trait BippyLike[A <: AnyRef, B <: List[A], This <: extest.BippyLike[A,B,This] with extest.Bippy[A,B]] extends AnyRef extest.BippyLike[A,B,This] forSome { A <: AnyRef; B <: List[A]; This <: extest.BippyLike[A,B,This] with extest.Bippy[A,B] } -abstract trait Contra[-A >: AnyRef, -B] extends Object +abstract trait Contra[-A >: AnyRef, -B] extends AnyRef extest.Contra[_ >: AnyRef, _] -abstract trait ContraLike[-A >: AnyRef, -B >: List[A]] extends Object +abstract trait ContraLike[-A >: AnyRef, -B >: List[A]] extends AnyRef extest.ContraLike[A,B] forSome { -A >: AnyRef; -B >: List[A] } -abstract trait Cov01[+A <: AnyRef, +B] extends Object +abstract trait Cov01[+A <: AnyRef, +B] extends AnyRef extest.Cov01[_ <: AnyRef, _] -abstract trait Cov02[+A <: AnyRef, B] extends Object +abstract trait Cov02[+A <: AnyRef, B] extends AnyRef extest.Cov02[_ <: AnyRef, _] -abstract trait Cov03[+A <: AnyRef, -B] extends Object +abstract trait Cov03[+A <: AnyRef, -B] extends AnyRef extest.Cov03[_ <: AnyRef, _] -abstract trait Cov04[A <: AnyRef, +B] extends Object +abstract trait Cov04[A <: AnyRef, +B] extends AnyRef extest.Cov04[_ <: AnyRef, _] -abstract trait Cov05[A <: AnyRef, B] extends Object +abstract trait Cov05[A <: AnyRef, B] extends AnyRef extest.Cov05[_ <: AnyRef, _] -abstract trait Cov06[A <: AnyRef, -B] extends Object +abstract trait Cov06[A <: AnyRef, -B] extends AnyRef extest.Cov06[_ <: AnyRef, _] -abstract trait Cov07[-A <: AnyRef, +B] extends Object +abstract trait Cov07[-A <: AnyRef, +B] extends AnyRef extest.Cov07[_ <: AnyRef, _] -abstract trait Cov08[-A <: AnyRef, B] extends Object +abstract trait Cov08[-A <: AnyRef, B] extends AnyRef extest.Cov08[_ <: AnyRef, _] -abstract trait Cov09[-A <: AnyRef, -B] extends Object +abstract trait Cov09[-A <: AnyRef, -B] extends AnyRef extest.Cov09[_ <: AnyRef, _] -abstract trait Cov11[+A <: AnyRef, +B <: List[_]] extends Object +abstract trait Cov11[+A <: AnyRef, +B <: List[_]] extends AnyRef extest.Cov11[_ <: AnyRef, _ <: List[_]] -abstract trait Cov12[+A <: AnyRef, B <: List[_]] extends Object +abstract trait Cov12[+A <: AnyRef, B <: List[_]] extends AnyRef extest.Cov12[_ <: AnyRef, _ <: List[_]] -abstract trait Cov13[+A <: AnyRef, -B <: List[_]] extends Object +abstract trait Cov13[+A <: AnyRef, -B <: List[_]] extends AnyRef extest.Cov13[_ <: AnyRef, _ <: List[_]] -abstract trait Cov14[A <: AnyRef, +B <: List[_]] extends Object +abstract trait Cov14[A <: AnyRef, +B <: List[_]] extends AnyRef extest.Cov14[_ <: AnyRef, _ <: List[_]] -abstract trait Cov15[A <: AnyRef, B <: List[_]] extends Object +abstract trait Cov15[A <: AnyRef, B <: List[_]] extends AnyRef extest.Cov15[_ <: AnyRef, _ <: List[_]] -abstract trait Cov16[A <: AnyRef, -B <: List[_]] extends Object +abstract trait Cov16[A <: AnyRef, -B <: List[_]] extends AnyRef extest.Cov16[_ <: AnyRef, _ <: List[_]] -abstract trait Cov17[-A <: AnyRef, +B <: List[_]] extends Object +abstract trait Cov17[-A <: AnyRef, +B <: List[_]] extends AnyRef extest.Cov17[_ <: AnyRef, _ <: List[_]] -abstract trait Cov18[-A <: AnyRef, B <: List[_]] extends Object +abstract trait Cov18[-A <: AnyRef, B <: List[_]] extends AnyRef extest.Cov18[_ <: AnyRef, _ <: List[_]] -abstract trait Cov19[-A <: AnyRef, -B <: List[_]] extends Object +abstract trait Cov19[-A <: AnyRef, -B <: List[_]] extends AnyRef extest.Cov19[_ <: AnyRef, _ <: List[_]] -abstract trait Cov21[+A, +B] extends Object +abstract trait Cov21[+A, +B] extends AnyRef extest.Cov21[_, _] -abstract trait Cov22[+A, B] extends Object +abstract trait Cov22[+A, B] extends AnyRef extest.Cov22[_, _] -abstract trait Cov23[+A, -B] extends Object +abstract trait Cov23[+A, -B] extends AnyRef extest.Cov23[_, _] -abstract trait Cov24[A, +B] extends Object +abstract trait Cov24[A, +B] extends AnyRef extest.Cov24[_, _] -abstract trait Cov25[A, B] extends Object +abstract trait Cov25[A, B] extends AnyRef extest.Cov25[_, _] -abstract trait Cov26[A, -B] extends Object +abstract trait Cov26[A, -B] extends AnyRef extest.Cov26[_, _] -abstract trait Cov27[-A, +B] extends Object +abstract trait Cov27[-A, +B] extends AnyRef extest.Cov27[_, _] -abstract trait Cov28[-A, B] extends Object +abstract trait Cov28[-A, B] extends AnyRef extest.Cov28[_, _] -abstract trait Cov29[-A, -B] extends Object +abstract trait Cov29[-A, -B] extends AnyRef extest.Cov29[_, _] -abstract trait Cov31[+A, +B, C <: (A, B)] extends Object +abstract trait Cov31[+A, +B, C <: (A, B)] extends AnyRef extest.Cov31[A,B,C] forSome { +A; +B; C <: (A, B) } -abstract trait Cov32[+A, B, C <: (A, B)] extends Object +abstract trait Cov32[+A, B, C <: (A, B)] extends AnyRef extest.Cov32[A,B,C] forSome { +A; B; C <: (A, B) } -abstract trait Cov33[+A, -B, C <: Tuple2[A, _]] extends Object +abstract trait Cov33[+A, -B, C <: Tuple2[A, _]] extends AnyRef extest.Cov33[A,B,C] forSome { +A; -B; C <: Tuple2[A, _] } -abstract trait Cov34[A, +B, C <: (A, B)] extends Object +abstract trait Cov34[A, +B, C <: (A, B)] extends AnyRef extest.Cov34[A,B,C] forSome { A; +B; C <: (A, B) } -abstract trait Cov35[A, B, C <: (A, B)] extends Object +abstract trait Cov35[A, B, C <: (A, B)] extends AnyRef extest.Cov35[A,B,C] forSome { A; B; C <: (A, B) } -abstract trait Cov36[A, -B, C <: Tuple2[A, _]] extends Object +abstract trait Cov36[A, -B, C <: Tuple2[A, _]] extends AnyRef extest.Cov36[A,B,C] forSome { A; -B; C <: Tuple2[A, _] } -abstract trait Cov37[-A, +B, C <: Tuple2[_, B]] extends Object +abstract trait Cov37[-A, +B, C <: Tuple2[_, B]] extends AnyRef extest.Cov37[A,B,C] forSome { -A; +B; C <: Tuple2[_, B] } -abstract trait Cov38[-A, B, C <: Tuple2[_, B]] extends Object +abstract trait Cov38[-A, B, C <: Tuple2[_, B]] extends AnyRef extest.Cov38[A,B,C] forSome { -A; B; C <: Tuple2[_, B] } -abstract trait Cov39[-A, -B, C <: Tuple2[_, _]] extends Object +abstract trait Cov39[-A, -B, C <: Tuple2[_, _]] extends AnyRef extest.Cov39[_, _, _ <: Tuple2[_, _]] -abstract trait Cov41[+A >: Null, +B] extends Object +abstract trait Cov41[+A >: Null, +B] extends AnyRef extest.Cov41[_ >: Null, _] -abstract trait Cov42[+A >: Null, B] extends Object +abstract trait Cov42[+A >: Null, B] extends AnyRef extest.Cov42[_ >: Null, _] -abstract trait Cov43[+A >: Null, -B] extends Object +abstract trait Cov43[+A >: Null, -B] extends AnyRef extest.Cov43[_ >: Null, _] -abstract trait Cov44[A >: Null, +B] extends Object +abstract trait Cov44[A >: Null, +B] extends AnyRef extest.Cov44[_ >: Null, _] -abstract trait Cov45[A >: Null, B] extends Object +abstract trait Cov45[A >: Null, B] extends AnyRef extest.Cov45[_ >: Null, _] -abstract trait Cov46[A >: Null, -B] extends Object +abstract trait Cov46[A >: Null, -B] extends AnyRef extest.Cov46[_ >: Null, _] -abstract trait Cov47[-A >: Null, +B] extends Object +abstract trait Cov47[-A >: Null, +B] extends AnyRef extest.Cov47[_ >: Null, _] -abstract trait Cov48[-A >: Null, B] extends Object +abstract trait Cov48[-A >: Null, B] extends AnyRef extest.Cov48[_ >: Null, _] -abstract trait Cov49[-A >: Null, -B] extends Object +abstract trait Cov49[-A >: Null, -B] extends AnyRef extest.Cov49[_ >: Null, _] -abstract trait Covariant[+A <: AnyRef, +B] extends Object +abstract trait Covariant[+A <: AnyRef, +B] extends AnyRef extest.Covariant[_ <: AnyRef, _] -abstract trait CovariantLike[+A <: AnyRef, +B <: List[A], +This <: extest.CovariantLike[A,B,This] with extest.Covariant[A,B]] extends Object +abstract trait CovariantLike[+A <: AnyRef, +B <: List[A], +This <: extest.CovariantLike[A,B,This] with extest.Covariant[A,B]] extends AnyRef extest.CovariantLike[A,B,This] forSome { +A <: AnyRef; +B <: List[A]; +This <: extest.CovariantLike[A,B,This] with extest.Covariant[A,B] } diff --git a/test/files/run/existentials3-new.check b/test/files/run/existentials3-new.check index 00614b19db..8f7dd701ac 100644 --- a/test/files/run/existentials3-new.check +++ b/test/files/run/existentials3-new.check @@ -7,7 +7,7 @@ Test.ToS, t=RefinedType, s=f5 () => Test.ToS, t=TypeRef, s=trait Function0 $anon, t=TypeRef, s=type $anon $anon, t=TypeRef, s=type $anon -List[java.lang.Object{type T1}#T1], t=TypeRef, s=class List +List[AnyRef{type T1}#T1], t=TypeRef, s=class List List[Seq[Int]], t=TypeRef, s=class List List[Seq[U forSome { type U <: Int }]], t=TypeRef, s=class List Bar.type, t=TypeRef, s=type Bar.type @@ -19,6 +19,6 @@ Test.ToS, t=RefinedType, s=g5 () => Test.ToS, t=TypeRef, s=trait Function0 $anon, t=TypeRef, s=type $anon $anon, t=TypeRef, s=type $anon -List[java.lang.Object{type T1}#T1], t=TypeRef, s=class List +List[AnyRef{type T1}#T1], t=TypeRef, s=class List List[Seq[Int]], t=TypeRef, s=class List List[Seq[U forSome { type U <: Int }]], t=TypeRef, s=class List diff --git a/test/files/run/macro-declared-in-trait.check b/test/files/run/macro-declared-in-trait.check index 104ff1e99b..0d70ac74f3 100644 --- a/test/files/run/macro-declared-in-trait.check +++ b/test/files/run/macro-declared-in-trait.check @@ -1,5 +1,5 @@ prefix = Expr[Nothing]({ - final class $anon extends Object with Base { + final class $anon extends AnyRef with Base { def (): anonymous class $anon = { $anon.super.(); () diff --git a/test/files/run/reflection-equality.check b/test/files/run/reflection-equality.check index 17c1f6dd70..65b525731f 100644 --- a/test/files/run/reflection-equality.check +++ b/test/files/run/reflection-equality.check @@ -24,7 +24,7 @@ cs: reflect.runtime.universe.ClassSymbol = class X scala> val ts: Type = cs.typeSignature ts: reflect.runtime.universe.Type = -java.lang.Object { +scala.AnyRef { def (): X def methodIntIntInt(x: scala.Int,y: scala.Int): scala.Int } diff --git a/test/files/run/repl-colon-type.check b/test/files/run/repl-colon-type.check index 7716221f54..4cd0e1d588 100644 --- a/test/files/run/repl-colon-type.check +++ b/test/files/run/repl-colon-type.check @@ -75,10 +75,10 @@ scala> :type -v List(1,2,3) filter _ // Internal Type structure TypeRef( - TypeSymbol(abstract trait Function1[-T1, +R] extends Object) + TypeSymbol(abstract trait Function1[-T1, +R] extends AnyRef) args = List( TypeRef( - TypeSymbol(abstract trait Function1[-T1, +R] extends Object) + TypeSymbol(abstract trait Function1[-T1, +R] extends AnyRef) args = List( TypeRef(TypeSymbol(final abstract class Int extends AnyVal)) TypeRef( @@ -145,7 +145,7 @@ Int => Iterator[List[Nothing]] // Internal Type structure TypeRef( - TypeSymbol(abstract trait Function1[-T1, +R] extends Object) + TypeSymbol(abstract trait Function1[-T1, +R] extends AnyRef) args = List( TypeRef(TypeSymbol(final abstract class Int extends AnyVal)) TypeRef( @@ -178,7 +178,7 @@ PolyType( typeParams = List(TypeParam(T <: AnyVal)) resultType = NullaryMethodType( TypeRef( - TypeSymbol(abstract trait Function1[-T1, +R] extends Object) + TypeSymbol(abstract trait Function1[-T1, +R] extends AnyRef) args = List( TypeRef(TypeSymbol(final abstract class Int extends AnyVal)) TypeRef( diff --git a/test/files/run/repl-parens.check b/test/files/run/repl-parens.check index 4b7ce6b059..15f4b4524a 100644 --- a/test/files/run/repl-parens.check +++ b/test/files/run/repl-parens.check @@ -66,7 +66,7 @@ scala> 55 ; () => 5 res13: () => Int = scala> () => { class X ; new X } -res14: () => Object = +res14: () => AnyRef = scala> diff --git a/test/files/run/t4172.check b/test/files/run/t4172.check index f16c9e5151..94cdff4870 100644 --- a/test/files/run/t4172.check +++ b/test/files/run/t4172.check @@ -5,7 +5,7 @@ scala> scala> val c = { class C { override def toString = "C" }; ((new C, new C { def f = 2 })) } warning: there were 1 feature warnings; re-run with -feature for details -c: (C, C{def f: Int}) forSome { type C <: Object } = (C,C) +c: (C, C{def f: Int}) forSome { type C <: AnyRef } = (C,C) scala> diff --git a/test/files/run/t5256a.check b/test/files/run/t5256a.check index 7e60139db3..09b5a02831 100644 --- a/test/files/run/t5256a.check +++ b/test/files/run/t5256a.check @@ -1,6 +1,6 @@ class A A -Object { +AnyRef { def (): A def foo: Nothing } diff --git a/test/files/run/t5256b.check b/test/files/run/t5256b.check index a80df6eb30..ca93aaa706 100644 --- a/test/files/run/t5256b.check +++ b/test/files/run/t5256b.check @@ -1,6 +1,6 @@ class A Test.A -Object { +AnyRef { def (): Test.A def foo: Nothing } diff --git a/test/files/run/t5256d.check b/test/files/run/t5256d.check index 9742ae572e..b7617e80a2 100644 --- a/test/files/run/t5256d.check +++ b/test/files/run/t5256d.check @@ -22,7 +22,7 @@ scala> println(c.fullName) $line8.$read.$iw.$iw.$iw.$iw.A scala> println(c.typeSignature) -java.lang.Object { +scala.AnyRef { def (): A def foo: scala.Nothing } diff --git a/test/files/run/t5256e.check b/test/files/run/t5256e.check index 011115720c..ed3513183e 100644 --- a/test/files/run/t5256e.check +++ b/test/files/run/t5256e.check @@ -1,6 +1,6 @@ class A Test.C.A -Object { +AnyRef { def (): C.this.A def foo: Nothing } diff --git a/test/files/run/t5256f.check b/test/files/run/t5256f.check index e0fec85596..6a89d0b86a 100644 --- a/test/files/run/t5256f.check +++ b/test/files/run/t5256f.check @@ -1,12 +1,12 @@ class A1 Test.A1 -Object { +AnyRef { def (): Test.A1 def foo: Nothing } class A2 Test.A2 -Object { +AnyRef { def (): Test.this.A2 def foo: Nothing } diff --git a/test/files/scalap/abstractClass/result.test b/test/files/scalap/abstractClass/result.test index 9163346fc6..ef1daac23d 100644 --- a/test/files/scalap/abstractClass/result.test +++ b/test/files/scalap/abstractClass/result.test @@ -1,4 +1,4 @@ -abstract class AbstractClass extends java.lang.Object { +abstract class AbstractClass extends scala.AnyRef { def this() = { /* compiled code */ } def foo : scala.Predef.String } diff --git a/test/files/scalap/abstractMethod/result.test b/test/files/scalap/abstractMethod/result.test index 90f572f258..40fa02d408 100644 --- a/test/files/scalap/abstractMethod/result.test +++ b/test/files/scalap/abstractMethod/result.test @@ -1,4 +1,4 @@ -trait AbstractMethod extends java.lang.Object { +trait AbstractMethod extends scala.AnyRef { def $init$() : scala.Unit = { /* compiled code */ } def arity : scala.Int def isCool : scala.Boolean = { /* compiled code */ } diff --git a/test/files/scalap/cbnParam/result.test b/test/files/scalap/cbnParam/result.test index fbe035d63c..52ecb6ae66 100644 --- a/test/files/scalap/cbnParam/result.test +++ b/test/files/scalap/cbnParam/result.test @@ -1,3 +1,3 @@ -class CbnParam extends java.lang.Object { +class CbnParam extends scala.AnyRef { def this(s : => scala.Predef.String) = { /* compiled code */ } } diff --git a/test/files/scalap/classPrivate/result.test b/test/files/scalap/classPrivate/result.test index 5f2e1cc00e..ab2d40cdaf 100644 --- a/test/files/scalap/classPrivate/result.test +++ b/test/files/scalap/classPrivate/result.test @@ -1,7 +1,7 @@ -class ClassPrivate extends java.lang.Object { +class ClassPrivate extends scala.AnyRef { def this() = { /* compiled code */ } def baz : scala.Int = { /* compiled code */ } - class Outer extends java.lang.Object { + class Outer extends scala.AnyRef { def this() = { /* compiled code */ } private[ClassPrivate] def qux : scala.Int = { /* compiled code */ } } diff --git a/test/files/scalap/classWithExistential/result.test b/test/files/scalap/classWithExistential/result.test index b8ce005da9..caee3fd6de 100644 --- a/test/files/scalap/classWithExistential/result.test +++ b/test/files/scalap/classWithExistential/result.test @@ -1,4 +1,4 @@ -class ClassWithExistential extends java.lang.Object { +class ClassWithExistential extends scala.AnyRef { def this() = { /* compiled code */ } def foo[A, B] : scala.Function1[A, B forSome {type A <: scala.Seq[scala.Int]; type B >: scala.Predef.String}] = { /* compiled code */ } } diff --git a/test/files/scalap/classWithSelfAnnotation/result.test b/test/files/scalap/classWithSelfAnnotation/result.test index df7bd86643..82bbd9e8df 100644 --- a/test/files/scalap/classWithSelfAnnotation/result.test +++ b/test/files/scalap/classWithSelfAnnotation/result.test @@ -1,4 +1,4 @@ -class ClassWithSelfAnnotation extends java.lang.Object { +class ClassWithSelfAnnotation extends scala.AnyRef { this : ClassWithSelfAnnotation with java.lang.CharSequence => def this() = { /* compiled code */ } def foo : scala.Int = { /* compiled code */ } diff --git a/test/files/scalap/covariantParam/result.test b/test/files/scalap/covariantParam/result.test index 2f52f1f28e..f7a3c98966 100644 --- a/test/files/scalap/covariantParam/result.test +++ b/test/files/scalap/covariantParam/result.test @@ -1,4 +1,4 @@ -class CovariantParam[+A] extends java.lang.Object { +class CovariantParam[+A] extends scala.AnyRef { def this() = { /* compiled code */ } def foo[A](a : A) : scala.Int = { /* compiled code */ } } diff --git a/test/files/scalap/defaultParameter/result.test b/test/files/scalap/defaultParameter/result.test index 38bf6ac4e3..0c775ea7b5 100644 --- a/test/files/scalap/defaultParameter/result.test +++ b/test/files/scalap/defaultParameter/result.test @@ -1,3 +1,3 @@ -trait DefaultParameter extends java.lang.Object { +trait DefaultParameter extends scala.AnyRef { def foo(s : scala.Predef.String) : scala.Unit -} \ No newline at end of file +} diff --git a/test/files/scalap/implicitParam/result.test b/test/files/scalap/implicitParam/result.test index 0ea212dda6..a2cfd6092d 100644 --- a/test/files/scalap/implicitParam/result.test +++ b/test/files/scalap/implicitParam/result.test @@ -1,4 +1,4 @@ -class ImplicitParam extends java.lang.Object { +class ImplicitParam extends scala.AnyRef { def this() = { /* compiled code */ } def foo(i : scala.Int)(implicit f : scala.Float, d : scala.Double) : scala.Int = { /* compiled code */ } } diff --git a/test/files/scalap/packageObject/result.test b/test/files/scalap/packageObject/result.test index 94c6a01b08..5732d92958 100644 --- a/test/files/scalap/packageObject/result.test +++ b/test/files/scalap/packageObject/result.test @@ -1,4 +1,4 @@ -package object PackageObject extends java.lang.Object { +package object PackageObject extends scala.AnyRef { def this() = { /* compiled code */ } type A = scala.Predef.String def foo(i : scala.Int) : scala.Int = { /* compiled code */ } diff --git a/test/files/scalap/paramClauses/result.test b/test/files/scalap/paramClauses/result.test index dc4397386c..3a141e8faf 100644 --- a/test/files/scalap/paramClauses/result.test +++ b/test/files/scalap/paramClauses/result.test @@ -1,4 +1,4 @@ -class ParamClauses extends java.lang.Object { +class ParamClauses extends scala.AnyRef { def this() = { /* compiled code */ } def foo(i : scala.Int)(s : scala.Predef.String)(t : scala.Double) : scala.Int = { /* compiled code */ } } diff --git a/test/files/scalap/paramNames/result.test b/test/files/scalap/paramNames/result.test index 4d3c7d0c1e..85e37f858d 100644 --- a/test/files/scalap/paramNames/result.test +++ b/test/files/scalap/paramNames/result.test @@ -1,4 +1,4 @@ -class ParamNames extends java.lang.Object { +class ParamNames extends scala.AnyRef { def this() = { /* compiled code */ } def foo(s : => scala.Seq[scala.Int], s2 : => scala.Seq[scala.Any]) : scala.Unit = { /* compiled code */ } } diff --git a/test/files/scalap/sequenceParam/result.test b/test/files/scalap/sequenceParam/result.test index ed47c094fe..142d92fea3 100644 --- a/test/files/scalap/sequenceParam/result.test +++ b/test/files/scalap/sequenceParam/result.test @@ -1,3 +1,3 @@ -class SequenceParam extends java.lang.Object { +class SequenceParam extends scala.AnyRef { def this(s : scala.Predef.String, i : scala.Int*) = { /* compiled code */ } } diff --git a/test/files/scalap/simpleClass/result.test b/test/files/scalap/simpleClass/result.test index 905046ce52..4fdf25d1cf 100644 --- a/test/files/scalap/simpleClass/result.test +++ b/test/files/scalap/simpleClass/result.test @@ -1,4 +1,4 @@ -class SimpleClass extends java.lang.Object { +class SimpleClass extends scala.AnyRef { def this() = { /* compiled code */ } def foo : scala.Int = { /* compiled code */ } } diff --git a/test/files/scalap/traitObject/result.test b/test/files/scalap/traitObject/result.test index d0521043c8..104ba14f1a 100644 --- a/test/files/scalap/traitObject/result.test +++ b/test/files/scalap/traitObject/result.test @@ -1,8 +1,8 @@ -trait TraitObject extends java.lang.Object { +trait TraitObject extends scala.AnyRef { def $init$() : scala.Unit = { /* compiled code */ } def foo : scala.Int = { /* compiled code */ } } -object TraitObject extends java.lang.Object { +object TraitObject extends scala.AnyRef { def this() = { /* compiled code */ } def bar : scala.Int = { /* compiled code */ } } diff --git a/test/files/scalap/typeAnnotations/result.test b/test/files/scalap/typeAnnotations/result.test index d28712f12b..407b0235c6 100644 --- a/test/files/scalap/typeAnnotations/result.test +++ b/test/files/scalap/typeAnnotations/result.test @@ -1,4 +1,4 @@ -abstract class TypeAnnotations[@scala.specialized R] extends java.lang.Object { +abstract class TypeAnnotations[@scala.specialized R] extends scala.AnyRef { def this() = { /* compiled code */ } @scala.specialized val x : scala.Int = { /* compiled code */ } diff --git a/test/files/scalap/valAndVar/result.test b/test/files/scalap/valAndVar/result.test index 90081acade..e940da9801 100644 --- a/test/files/scalap/valAndVar/result.test +++ b/test/files/scalap/valAndVar/result.test @@ -1,4 +1,4 @@ -class ValAndVar extends java.lang.Object { +class ValAndVar extends scala.AnyRef { def this() = { /* compiled code */ } val foo : java.lang.String = { /* compiled code */ } var bar : scala.Int = { /* compiled code */ } diff --git a/test/files/scalap/wildcardType/result.test b/test/files/scalap/wildcardType/result.test index 28147b6605..e43261db32 100644 --- a/test/files/scalap/wildcardType/result.test +++ b/test/files/scalap/wildcardType/result.test @@ -1,3 +1,3 @@ -class WildcardType extends java.lang.Object { +class WildcardType extends scala.AnyRef { def this(f : scala.Function1[scala.Int, _]) = { /* compiled code */ } } -- cgit v1.2.3 From 422f461578ae0547181afe6d2c0c52ea1071d37b Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Sat, 22 Dec 2012 08:13:48 -0800 Subject: Shored up a hidden dealiasing dependency. Like the comment says: // This way typedNew always returns a dealiased type. This // used to happen by accident for instantiations without type // arguments due to ad hoc code in typedTypeConstructor, and // annotations depended on it (to the extent that they worked, // which they did not when given a parameterized type alias // which dealiased to an annotation.) typedTypeConstructor // dealiases nothing now, but it makes sense for a "new" to // always be given a dealiased type. PS: Simply running the test suite is becoming more difficult all the time. Running "ant test" includes time consuming activities of niche interest such as all the osgi tests, but test.suite manages to miss the continuations tests. --- src/compiler/scala/tools/nsc/typechecker/Typers.scala | 8 +++++++- test/files/continuations-neg/function2.check | 2 +- test/files/continuations-neg/t5314-type-error.check | 4 ++-- test/files/jvm/annotations.check | 15 +++++++++++++++ test/files/jvm/annotations.scala | 6 ++++++ 5 files changed, 31 insertions(+), 4 deletions(-) (limited to 'test/files') diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index ad2ec7ff6c..abc5baff72 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -4208,7 +4208,13 @@ trait Typers extends Modes with Adaptations with Tags { def typedNew(tree: New) = { val tpt = tree.tpt val tpt1 = { - val tpt0 = typedTypeConstructor(tpt) + // This way typedNew always returns a dealiased type. This used to happen by accident + // for instantiations without type arguments due to ad hoc code in typedTypeConstructor, + // and annotations depended on it (to the extent that they worked, which they did + // not when given a parameterized type alias which dealiased to an annotation.) + // typedTypeConstructor dealiases nothing now, but it makes sense for a "new" to always be + // given a dealiased type. + val tpt0 = typedTypeConstructor(tpt) modifyType (_.dealias) if (checkStablePrefixClassType(tpt0)) if (tpt0.hasSymbolField && !tpt0.symbol.typeParams.isEmpty) { context.undetparams = cloneSymbols(tpt0.symbol.typeParams) diff --git a/test/files/continuations-neg/function2.check b/test/files/continuations-neg/function2.check index 82b81c1444..4b1a6227bc 100644 --- a/test/files/continuations-neg/function2.check +++ b/test/files/continuations-neg/function2.check @@ -1,6 +1,6 @@ function2.scala:11: error: type mismatch; found : () => Int - required: () => Int @util.continuations.cps[Int] + required: () => Int @scala.util.continuations.cpsParam[Int,Int] val g: () => Int @cps[Int] = f ^ one error found diff --git a/test/files/continuations-neg/t5314-type-error.check b/test/files/continuations-neg/t5314-type-error.check index 1f4e46a7f2..e66c9d833f 100644 --- a/test/files/continuations-neg/t5314-type-error.check +++ b/test/files/continuations-neg/t5314-type-error.check @@ -1,6 +1,6 @@ t5314-type-error.scala:7: error: type mismatch; - found : Int @util.continuations.cps[Int] - required: Int @util.continuations.cps[String] + found : Int @scala.util.continuations.cpsParam[Int,Int] + required: Int @scala.util.continuations.cpsParam[String,String] def bar(x:Int): Int @cps[String] = return foo(x) ^ one error found diff --git a/test/files/jvm/annotations.check b/test/files/jvm/annotations.check index 8a4d58d56c..a8dc5ecdd1 100644 --- a/test/files/jvm/annotations.check +++ b/test/files/jvm/annotations.check @@ -28,6 +28,21 @@ public Test4$Foo8(int) @test.SourceAnnotation(mails={bill.gates@bloodsuckers.com}, value=http://eppli.com) private int Test4$Foo9.z +@test.SourceAnnotation(mails={bill.gates@bloodsuckers.com}, value=http://eppli.com) +private int Test4$Foo9.z2 + +@test.SourceAnnotation(mails={bill.gates@bloodsuckers.com}, value=http://eppli.com) +private int Test4$Foo9.z3 + +@test.SourceAnnotation(mails={bill.gates@bloodsuckers.com}, value=http://eppli.com) +public int Test4$Foo9.getZ() + +@test.SourceAnnotation(mails={bill.gates@bloodsuckers.com}, value=http://eppli.com) +public int Test4$Foo9.getZ2() + +@test.SourceAnnotation(mails={bill.gates@bloodsuckers.com}, value=http://eppli.com) +public int Test4$Foo9.getZ3() + @test.SourceAnnotation(mails={bill.gates@bloodsuckers.com}, value=http://apple.com) public int Test4$Foo9.x() diff --git a/test/files/jvm/annotations.scala b/test/files/jvm/annotations.scala index 66ebde592b..77a45fae89 100644 --- a/test/files/jvm/annotations.scala +++ b/test/files/jvm/annotations.scala @@ -101,6 +101,12 @@ object Test4 { type myAnn = SourceAnnotation @beanGetter @field @BeanProperty @myAnn("http://eppli.com") var z = 0 + + type myAnn2[T] = SourceAnnotation @beanGetter @field + @BeanProperty @myAnn2[String]("http://eppli.com") var z2 = 0 + + type myAnn3[CC[_]] = SourceAnnotation @beanGetter @field + @BeanProperty @myAnn3[List]("http://eppli.com") var z3 = 0 } class Foo10(@SourceAnnotation("on param 1") val name: String) class Foo11(@(SourceAnnotation @scala.annotation.meta.field)("on param 2") val name: String) -- cgit v1.2.3 From 3bf51189f979eb0dd41744ca844fd12dfdaa0dee Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Fri, 21 Dec 2012 15:11:29 -0800 Subject: Cleaning up type alias usage. I determined that many if not most of the calls to .normalize have no intent beyond dealiasing the type. In light of this I went call site to call site knocking on doors and asking why exactly they were calling any of .normalize .widen.normalize .normalize.widen and if I didn't like their answers they found themselves introduced to 'dropAliasesAndSingleTypes', the recursive widener and dealiaser which I concluded is necessary after all. Discovered that the object called 'deAlias' actually depends upon calling 'normalize', not 'dealias'. Decided this was sufficient cause to rename it to 'normalizeAliases'. Created dealiasWiden and dealiasWidenChain. Dropped dropAliasesAndSingleTypes in favor of methods on Type alongside dealias and widen (Type#dealiasWiden). These should reduce the number of "hey, the type alias doesn't work" bugs. --- .../tools/nsc/interpreter/CompletionOutput.scala | 8 ++--- .../scala/tools/nsc/interpreter/IMain.scala | 2 +- .../scala/tools/nsc/typechecker/Implicits.scala | 31 ++++++++-------- .../scala/tools/nsc/typechecker/Infer.scala | 6 ++-- .../scala/tools/nsc/typechecker/Typers.scala | 18 +++++----- src/reflect/scala/reflect/internal/Types.scala | 41 +++++++++++++++++----- test/files/run/existentials3-old.check | 4 +-- 7 files changed, 65 insertions(+), 45 deletions(-) (limited to 'test/files') diff --git a/src/compiler/scala/tools/nsc/interpreter/CompletionOutput.scala b/src/compiler/scala/tools/nsc/interpreter/CompletionOutput.scala index c647ef6f51..c5bb8494ce 100644 --- a/src/compiler/scala/tools/nsc/interpreter/CompletionOutput.scala +++ b/src/compiler/scala/tools/nsc/interpreter/CompletionOutput.scala @@ -37,7 +37,7 @@ trait CompletionOutput { val pkg = method.ownerChain find (_.isPackageClass) map (_.fullName) getOrElse "" def relativize(str: String): String = quietString(str stripPrefix (pkg + ".")) - def relativize(tp: Type): String = relativize(tp.normalize.toString) + def relativize(tp: Type): String = relativize(tp.dealiasWiden.toString) def braceList(tparams: List[String]) = if (tparams.isEmpty) "" else (tparams map relativize).mkString("[", ", ", "]") def parenList(params: List[Any]) = params.mkString("(", ", ", ")") @@ -55,8 +55,8 @@ trait CompletionOutput { } ) - def tupleString(tp: Type) = parenList(tp.normalize.typeArgs map relativize) - def functionString(tp: Type) = tp.normalize.typeArgs match { + def tupleString(tp: Type) = parenList(tp.dealiasWiden.typeArgs map relativize) + def functionString(tp: Type) = tp.dealiasWiden.typeArgs match { case List(t, r) => t + " => " + r case xs => parenList(xs.init) + " => " + xs.last } @@ -64,7 +64,7 @@ trait CompletionOutput { def tparamsString(tparams: List[Symbol]) = braceList(tparams map (_.defString)) def paramsString(params: List[Symbol]) = { def paramNameString(sym: Symbol) = if (sym.isSynthetic) "" else sym.nameString + ": " - def paramString(sym: Symbol) = paramNameString(sym) + typeToString(sym.info.normalize) + def paramString(sym: Symbol) = paramNameString(sym) + typeToString(sym.info.dealiasWiden) val isImplicit = params.nonEmpty && params.head.isImplicit val strs = (params map paramString) match { diff --git a/src/compiler/scala/tools/nsc/interpreter/IMain.scala b/src/compiler/scala/tools/nsc/interpreter/IMain.scala index 91e909b1f1..36f012229e 100644 --- a/src/compiler/scala/tools/nsc/interpreter/IMain.scala +++ b/src/compiler/scala/tools/nsc/interpreter/IMain.scala @@ -523,7 +523,7 @@ class IMain(initialSettings: Settings, protected val out: JPrintWriter) extends // normalize non-public types so we don't see protected aliases like Self def normalizeNonPublic(tp: Type) = tp match { - case TypeRef(_, sym, _) if sym.isAliasType && !sym.isPublic => tp.normalize + case TypeRef(_, sym, _) if sym.isAliasType && !sym.isPublic => tp.dealias case _ => tp } diff --git a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala index 8d6e0c3b85..ed1e6d01e8 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala @@ -439,8 +439,8 @@ trait Implicits { val start = if (Statistics.canEnable) Statistics.startTimer(matchesPtNanos) else null val result = normSubType(tp, pt) || isView && { pt match { - case TypeRef(_, Function1.Sym, args) => - matchesPtView(tp, args.head, args.tail.head, undet) + case TypeRef(_, Function1.Sym, arg1 :: arg2 :: Nil) => + matchesPtView(tp, arg1, arg2, undet) case _ => false } @@ -484,7 +484,7 @@ trait Implicits { loop(restpe, pt) else pt match { case tr @ TypeRef(pre, sym, args) => - if (sym.isAliasType) loop(tp, pt.normalize) + if (sym.isAliasType) loop(tp, pt.dealias) else if (sym.isAbstractType) loop(tp, pt.bounds.lo) else { val len = args.length - 1 @@ -528,18 +528,15 @@ trait Implicits { * to a final true or false. */ private def isPlausiblySubType(tp1: Type, tp2: Type) = !isImpossibleSubType(tp1, tp2) - private def isImpossibleSubType(tp1: Type, tp2: Type) = tp1.normalize.widen match { - case tr1 @ TypeRef(_, sym1, _) => - // We can only rule out a subtype relationship if the left hand - // side is a class, else we may not know enough. - sym1.isClass && (tp2.normalize.widen match { - case TypeRef(_, sym2, _) => - sym2.isClass && !(sym1 isWeakSubClass sym2) - case RefinedType(parents, decls) => - decls.nonEmpty && - tr1.member(decls.head.name) == NoSymbol - case _ => false - }) + private def isImpossibleSubType(tp1: Type, tp2: Type) = tp1.dealiasWiden match { + // We can only rule out a subtype relationship if the left hand + // side is a class, else we may not know enough. + case tr1 @ TypeRef(_, sym1, _) if sym1.isClass => + tp2.dealiasWiden match { + case TypeRef(_, sym2, _) => sym2.isClass && !(sym1 isWeakSubClass sym2) + case RefinedType(parents, decls) => decls.nonEmpty && tr1.member(decls.head.name) == NoSymbol + case _ => false + } case _ => false } @@ -1010,7 +1007,7 @@ trait Implicits { args foreach (getParts(_)) } } else if (sym.isAliasType) { - getParts(tp.normalize) + getParts(tp.dealias) } else if (sym.isAbstractType) { getParts(tp.bounds.hi) } @@ -1168,7 +1165,7 @@ trait Implicits { implicit def wrapResult(tree: Tree): SearchResult = if (tree == EmptyTree) SearchFailure else new SearchResult(tree, if (from.isEmpty) EmptyTreeTypeSubstituter else new TreeTypeSubstituter(from, to)) - val tp1 = tp0.normalize + val tp1 = tp0.dealias tp1 match { case ThisType(_) | SingleType(_, _) => // can't generate a reference to a value that's abstracted over by an existential diff --git a/src/compiler/scala/tools/nsc/typechecker/Infer.scala b/src/compiler/scala/tools/nsc/typechecker/Infer.scala index 2693fcfd27..a43dbae1fa 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Infer.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Infer.scala @@ -43,7 +43,7 @@ trait Infer extends Checkable { case formal => formal } else formals if (isVarArgTypes(formals1) && (removeRepeated || formals.length != nargs)) { - val ft = formals1.last.normalize.typeArgs.head + val ft = formals1.last.dealiasWiden.typeArgs.head formals1.init ::: (for (i <- List.range(formals1.length - 1, nargs)) yield ft) } else formals1 } @@ -1437,9 +1437,9 @@ trait Infer extends Checkable { } object approximateAbstracts extends TypeMap { - def apply(tp: Type): Type = tp.normalize match { + def apply(tp: Type): Type = tp.dealiasWiden match { case TypeRef(pre, sym, _) if sym.isAbstractType => WildcardType - case _ => mapOver(tp) + case _ => mapOver(tp) } } diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index abc5baff72..b5f456d1ae 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -13,7 +13,7 @@ package scala.tools.nsc package typechecker import scala.collection.mutable -import scala.reflect.internal.util.{ BatchSourceFile, Statistics } +import scala.reflect.internal.util.{ BatchSourceFile, Statistics, shortClassOfInstance } import mutable.ListBuffer import symtab.Flags._ @@ -227,7 +227,7 @@ trait Typers extends Modes with Adaptations with Tags { case ExistentialType(tparams, tpe) => new SubstWildcardMap(tparams).apply(tp) case TypeRef(_, sym, _) if sym.isAliasType => - val tp0 = tp.normalize + val tp0 = tp.dealias val tp1 = dropExistential(tp0) if (tp1 eq tp0) tp else tp1 case _ => tp @@ -413,7 +413,7 @@ trait Typers extends Modes with Adaptations with Tags { if (!hiddenSymbols.isEmpty && hiddenSymbols.head == sym && sym.isAliasType && sameLength(sym.typeParams, args)) { hiddenSymbols = hiddenSymbols.tail - t.normalize + t.dealias } else t case SingleType(_, sym) => checkNoEscape(sym) @@ -1033,9 +1033,9 @@ trait Typers extends Modes with Adaptations with Tags { adapt(tree setType restpe, mode, pt, original) case TypeRef(_, ByNameParamClass, List(arg)) if ((mode & EXPRmode) != 0) => // (2) adapt(tree setType arg, mode, pt, original) - case tr @ TypeRef(_, sym, _) if sym.isAliasType && tr.normalize.isInstanceOf[ExistentialType] && + case tr @ TypeRef(_, sym, _) if sym.isAliasType && tr.dealias.isInstanceOf[ExistentialType] && ((mode & (EXPRmode | LHSmode)) == EXPRmode) => - adapt(tree setType tr.normalize.skolemizeExistential(context.owner, tree), mode, pt, original) + adapt(tree setType tr.dealias.skolemizeExistential(context.owner, tree), mode, pt, original) case et @ ExistentialType(_, _) if ((mode & (EXPRmode | LHSmode)) == EXPRmode) => adapt(tree setType et.skolemizeExistential(context.owner, tree), mode, pt, original) case PolyType(tparams, restpe) if inNoModes(mode, TAPPmode | PATTERNmode | HKmode) => // (3) @@ -1105,7 +1105,7 @@ trait Typers extends Modes with Adaptations with Tags { if (tree1.tpe <:< pt) adapt(tree1, mode, pt, original) else { if (inExprModeButNot(mode, FUNmode)) { - pt.normalize match { + pt.dealias match { case TypeRef(_, sym, _) => // note: was if (pt.typeSymbol == UnitClass) but this leads to a potentially // infinite expansion if pt is constant type () @@ -1251,7 +1251,7 @@ trait Typers extends Modes with Adaptations with Tags { def adaptToMember(qual: Tree, searchTemplate: Type, reportAmbiguous: Boolean = true, saveErrors: Boolean = true): Tree = { if (isAdaptableWithView(qual)) { - qual.tpe.widen.normalize match { + qual.tpe.dealiasWiden match { case et: ExistentialType => qual setType et.skolemizeExistential(context.owner, qual) // open the existential case _ => @@ -1766,7 +1766,7 @@ trait Typers extends Modes with Adaptations with Tags { _.typedTemplate(cdef.impl, parentTypes(cdef.impl)) } val impl2 = finishMethodSynthesis(impl1, clazz, context) - if (clazz.isTrait && clazz.info.parents.nonEmpty && clazz.info.firstParent.normalize.typeSymbol == AnyClass) + if (clazz.isTrait && clazz.info.parents.nonEmpty && clazz.info.firstParent.typeSymbol == AnyClass) checkEphemeral(clazz, impl2.body) if ((clazz != ClassfileAnnotationClass) && (clazz isNonBottomSubClass ClassfileAnnotationClass)) @@ -3675,7 +3675,7 @@ trait Typers extends Modes with Adaptations with Tags { val normalizeLocals = new TypeMap { def apply(tp: Type): Type = tp match { case TypeRef(pre, sym, args) => - if (sym.isAliasType && containsLocal(tp)) apply(tp.normalize) + if (sym.isAliasType && containsLocal(tp)) apply(tp.dealias) else { if (pre.isVolatile) InferTypeWithVolatileTypeSelectionError(tree, pre) diff --git a/src/reflect/scala/reflect/internal/Types.scala b/src/reflect/scala/reflect/internal/Types.scala index 282d7e18ac..7a63699259 100644 --- a/src/reflect/scala/reflect/internal/Types.scala +++ b/src/reflect/scala/reflect/internal/Types.scala @@ -563,6 +563,26 @@ trait Types extends api.Types { self: SymbolTable => /** Expands type aliases. */ def dealias = this + /** Repeatedly apply widen and dealias until they have no effect. + * This compensates for the fact that type aliases can hide beneath + * singleton types and singleton types can hide inside type aliases. + */ + def dealiasWiden: Type = ( + if (this ne widen) widen.dealiasWiden + else if (this ne dealias) dealias.dealiasWiden + else this + ) + + /** All the types encountered in the course of dealiasing/widening, + * including each intermediate beta reduction step (whereas calling + * dealias applies as many as possible.) + */ + def dealiasWidenChain: List[Type] = this :: ( + if (this ne widen) widen.dealiasWidenChain + else if (this ne betaReduce) betaReduce.dealiasWidenChain + else Nil + ) + def etaExpand: Type = this /** Performs a single step of beta-reduction on types. @@ -3236,7 +3256,7 @@ trait Types extends api.Types { self: SymbolTable => if (constr.instValid) constr.inst // get here when checking higher-order subtyping of the typevar by itself // TODO: check whether this ever happens? - else if (isHigherKinded) typeFun(params, applyArgs(params map (_.typeConstructor))) + else if (isHigherKinded) logResult("Normalizing HK $this")(typeFun(params, applyArgs(params map (_.typeConstructor)))) else super.normalize ) override def typeSymbol = origin.typeSymbol @@ -3663,7 +3683,7 @@ trait Types extends api.Types { self: SymbolTable => def existentialAbstraction(tparams: List[Symbol], tpe0: Type): Type = if (tparams.isEmpty) tpe0 else { - val tpe = deAlias(tpe0) + val tpe = normalizeAliases(tpe0) val tpe1 = new ExistentialExtrapolation(tparams) extrapolate tpe var tparams0 = tparams var tparams1 = tparams0 filter tpe1.contains @@ -3677,13 +3697,16 @@ trait Types extends api.Types { self: SymbolTable => newExistentialType(tparams1, tpe1) } - /** Remove any occurrences of type aliases from this type */ - object deAlias extends TypeMap { - def apply(tp: Type): Type = mapOver { - tp match { - case TypeRef(pre, sym, args) if sym.isAliasType => tp.normalize - case _ => tp - } + /** Normalize any type aliases within this type (@see Type#normalize). + * Note that this depends very much on the call to "normalize", not "dealias", + * so it is no longer carries the too-stealthy name "deAlias". + */ + object normalizeAliases extends TypeMap { + def apply(tp: Type): Type = tp match { + case TypeRef(_, sym, _) if sym.isAliasType => + def msg = if (tp.isHigherKinded) s"Normalizing type alias function $tp" else s"Dealiasing type alias $tp" + mapOver(logResult(msg)(tp.normalize)) + case _ => mapOver(tp) } } diff --git a/test/files/run/existentials3-old.check b/test/files/run/existentials3-old.check index 72abfac637..36a458dacc 100644 --- a/test/files/run/existentials3-old.check +++ b/test/files/run/existentials3-old.check @@ -5,7 +5,7 @@ Object with Test$ToS Object with Test$ToS scala.Function0[Object with Test$ToS] scala.Function0[Object with Test$ToS] -_ <: Object with _ <: Object with Test$ToS +_ <: Object with _ <: Object with Object with Test$ToS _ <: Object with _ <: Object with _ <: Object with Test$ToS scala.collection.immutable.List[Object with scala.collection.Seq[Int]] scala.collection.immutable.List[Object with scala.collection.Seq[_ <: Int]] @@ -16,7 +16,7 @@ Object with Test$ToS Object with Test$ToS scala.Function0[Object with Test$ToS] scala.Function0[Object with Test$ToS] -_ <: Object with _ <: Object with Test$ToS +_ <: Object with _ <: Object with Object with Test$ToS _ <: Object with _ <: Object with _ <: Object with Test$ToS scala.collection.immutable.List[Object with scala.collection.Seq[Int]] scala.collection.immutable.List[Object with scala.collection.Seq[_ <: Int]] -- cgit v1.2.3 From dbebcd509e4013ce02655a2687b27d0967b3650e Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Wed, 19 Dec 2012 07:32:19 -0800 Subject: SI-6846, regression in type constructor inference. In 658ba1b4e6 some inference was gained and some was lost. In this commit we regain what was lost and gain even more. Dealiasing and widening should be fully handled now, as illustrated by the test case. --- .../scala/tools/nsc/typechecker/Infer.scala | 6 +++-- src/reflect/scala/reflect/internal/Types.scala | 19 +++++++-------- test/files/pos/t6846.scala | 28 ++++++++++++++++++++++ 3 files changed, 40 insertions(+), 13 deletions(-) create mode 100644 test/files/pos/t6846.scala (limited to 'test/files') diff --git a/src/compiler/scala/tools/nsc/typechecker/Infer.scala b/src/compiler/scala/tools/nsc/typechecker/Infer.scala index a43dbae1fa..7188290688 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Infer.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Infer.scala @@ -1122,15 +1122,17 @@ trait Infer extends Checkable { */ def inferExprInstance(tree: Tree, tparams: List[Symbol], pt: Type = WildcardType, treeTp0: Type = null, keepNothings: Boolean = true, useWeaklyCompatible: Boolean = false): List[Symbol] = { val treeTp = if(treeTp0 eq null) tree.tpe else treeTp0 // can't refer to tree in default for treeTp0 + val (targs, tvars) = exprTypeArgs(tparams, treeTp, pt, useWeaklyCompatible) printInference( ptBlock("inferExprInstance", "tree" -> tree, "tree.tpe"-> tree.tpe, "tparams" -> tparams, - "pt" -> pt + "pt" -> pt, + "targs" -> targs, + "tvars" -> tvars ) ) - val (targs, tvars) = exprTypeArgs(tparams, treeTp, pt, useWeaklyCompatible) if (keepNothings || (targs eq null)) { //@M: adjustTypeArgs fails if targs==null, neg/t0226 substExpr(tree, tparams, targs, pt) diff --git a/src/reflect/scala/reflect/internal/Types.scala b/src/reflect/scala/reflect/internal/Types.scala index 7a63699259..c121c6020e 100644 --- a/src/reflect/scala/reflect/internal/Types.scala +++ b/src/reflect/scala/reflect/internal/Types.scala @@ -3144,23 +3144,20 @@ trait Types extends api.Types { self: SymbolTable => * Checks subtyping of higher-order type vars, and uses variances as defined in the * type parameter we're trying to infer (the result will be sanity-checked later). */ - def unifyFull(tpe: Type) = { - // The alias/widen variations are often no-ops. - val tpes = ( - if (isLowerBound) List(tpe, tpe.widen, tpe.dealias, tpe.widen.dealias).distinct - else List(tpe) - ) - tpes exists { tp => - val lhs = if (isLowerBound) tp.typeArgs else typeArgs - val rhs = if (isLowerBound) typeArgs else tp.typeArgs - - sameLength(lhs, rhs) && { + def unifyFull(tpe: Type): Boolean = { + def unifySpecific(tp: Type) = { + sameLength(typeArgs, tp.typeArgs) && { + val lhs = if (isLowerBound) tp.typeArgs else typeArgs + val rhs = if (isLowerBound) typeArgs else tp.typeArgs // this is a higher-kinded type var with same arity as tp. // side effect: adds the type constructor itself as a bound addBound(tp.typeConstructor) isSubArgs(lhs, rhs, params, AnyDepth) } } + // The type with which we can successfully unify can be hidden + // behind singleton types and type aliases. + tpe.dealiasWidenChain exists unifySpecific } // There's a <: test taking place right now, where tp is a concrete type and this is a typevar diff --git a/test/files/pos/t6846.scala b/test/files/pos/t6846.scala new file mode 100644 index 0000000000..009566493f --- /dev/null +++ b/test/files/pos/t6846.scala @@ -0,0 +1,28 @@ +object Test { + class Arb[_] + implicit def foo[M[_], A]: Arb[M[A]] = null + foo: Arb[List[Int]] + type ListInt = List[Int] + foo: Arb[ListInt] +} + +object Test2 { + import scala.collection.immutable.List + + class Carb[_] + implicit def narrow[N, M[_], A](x: Carb[M[A]])(implicit ev: N <:< M[A]): Carb[N] = null + implicit def bar[M[_], A]: Carb[M[A]] = null + + type ListInt = List[Int] + + val x: List[Int] = List(1) + val y: ListInt = List(1) + + type ListSingletonX = x.type + type ListSingletonY = y.type + + bar: Carb[List[Int]] + bar: Carb[ListInt] + bar: Carb[ListSingletonX] + bar: Carb[ListSingletonY] +} -- cgit v1.2.3