summaryrefslogtreecommitdiff
path: root/test/files/run/t5294.scala
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2016-07-18 11:29:44 +1000
committerAdriaan Moors <adriaan.moors@typesafe.com>2016-08-23 15:51:51 -0700
commit893acc1829b3be96c75d00189e9e1b94ff4bd848 (patch)
tree4db52cd4b749e6b19a26ddffb248723276ef8b7a /test/files/run/t5294.scala
parent56f23af90732b3770770139b33f92852384c9f04 (diff)
downloadscala-893acc1829b3be96c75d00189e9e1b94ff4bd848.tar.gz
scala-893acc1829b3be96c75d00189e9e1b94ff4bd848.tar.bz2
scala-893acc1829b3be96c75d00189e9e1b94ff4bd848.zip
SI-5294 Use bounds of abstract prefix in asSeenFrom
ASF was failing to recognize the correspondence between a prefix if it has an abstract type symbol, even if it is bounded by the currently considered class. Distilling the test cases, this led to incorrect typechecking of the RHS of `G` in: ``` trait T { type A trait HasH { type H[U] <: U } type F[N <: HasH] = N#H[T] type G[N <: HasH] = F[N]#A // RHS was incorrectly reduced to T.this.A } ``` In the fuller examples (included as test cases), this meant that type level functions written as members of `HList` could not be implemented in terms of each other, e.g. defining `Apply[N]` as `Drop[N]#Head` had the wrong semantics. This commit checks checks if the prefix has the candidate class as a base type, rather than checking if its type symbol has this as a base class. The latter formulation discarded information about the instantation of the abstract type. Using the example above: ``` scala> val F = typeOf[T].member(TypeName("F")).info F: $r.intp.global.Type = [N <: T.this.HasH]N#H[T] scala> F.resultType.typeSymbol.baseClasses // old approach res14: List[$r.intp.global.Symbol] = List(class Any) scala> F.resultType.baseClasses // new approach res13: List[$r.intp.global.Symbol] = List(trait T, class Object, class Any) ``` It is worth noting that dotty rejects some of these programs, as it introduces the rule that: > // A type T is a legal prefix in a type selection T#A if > // T is stable or T contains no abstract types except possibly A. > final def isLegalPrefixFor(selector: Name)(implicit ctx: Context) However, typechecking the program above in this comment in dotty yields: <trait> trait T() extends Object { type A <trait> trait HasH() extends Object { type H <: [HK$0] => <: HK$0 } type F = [HK$0] => HK$0#H{HK$0 = T}#Apply type G = [HK$0] => HK$0#H{HK$0 = T}#Apply#A } As the equivalent code [1] in dotc's `asSeenFrom` already looks for a base type of the prefix, rather than looking for a superclass of the prefix's type symbol. [1] https://github.com/lampepfl/dotty/blob/d2c96d02fccef3a82b88ee1ff31253b6ef17f900/src/dotty/tools/dotc/core/TypeOps.scala#L62
Diffstat (limited to 'test/files/run/t5294.scala')
-rw-r--r--test/files/run/t5294.scala22
1 files changed, 22 insertions, 0 deletions
diff --git a/test/files/run/t5294.scala b/test/files/run/t5294.scala
new file mode 100644
index 0000000000..2551ae89a6
--- /dev/null
+++ b/test/files/run/t5294.scala
@@ -0,0 +1,22 @@
+import scala.language.higherKinds
+
+package p {
+ trait T[+A, +CC] {
+ def t: CC
+ }
+ class C {
+ def test[CC[X] <: T[X,String] with T[X,Int]](from: CC[_]): Unit = ()
+ }
+}
+
+object Test {
+ def main(args: Array[String]): Unit = {
+ val symtab = reflect.runtime.universe.asInstanceOf[reflect.internal.SymbolTable]
+ val CTpe = reflect.runtime.universe.typeOf[p.C].asInstanceOf[symtab.Type]
+ val TClass = reflect.runtime.universe.symbolOf[p.T[_, _]].asInstanceOf[symtab.Symbol]
+ import symtab._
+ val from = CTpe.member(TermName("test")).paramss.head.head
+ assert(from.baseClasses contains TClass)
+ assert(from.info.baseTypeIndex(TClass) != -1) // was failing!
+ }
+}