summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2014-02-17 22:13:19 +0100
committerJason Zaugg <jzaugg@gmail.com>2014-02-17 22:24:17 +0100
commitb31f9ab97912ad2d26df16ef223b874970175388 (patch)
tree64862658ba844ee760946cca1a8bfa7b68244696
parent6152e9c3153a9c028066abf6b91f6bf105eacdfe (diff)
downloadscala-b31f9ab97912ad2d26df16ef223b874970175388.tar.gz
scala-b31f9ab97912ad2d26df16ef223b874970175388.tar.bz2
scala-b31f9ab97912ad2d26df16ef223b874970175388.zip
SI-8301 fix regression with refinement subtyping, wildcard type.
In the enclosed test case, the list of candidate implicit is checked for eligibility with the view by: pt = Test.sym.type => ?{def asFreeType: ?} tp = (sym: Test.u.Symbol)Test.u.CompatibleSymbol matchesPt(tp, pt) This ends up in `TypeComparers#specializesSym`, which compares: symLo = asFreeType: => Universe.this.TypeSymbol symHi = asFreeType: ? Before the regression in fada1ef6, that method called `isStable` on both of these to make sure that `symLo` was as least as stable as `symHi`. Both returned `false`, and, they matched. After that refactoring, two calls were made. `isStable` *only* checked for stability, and gave the same results as before. But, the new check for volatility believes that the low symbol was more volatile than the high, because `WildCardType` is treated as non-volatile. Really, it should have the same volatility as whatever it is being compared to, so that these sort of comparisons yield true. This commit ammends `specializesSym` to special case `symHi: ?`, and ignore the volatilty gap in that case.
-rw-r--r--src/reflect/scala/reflect/internal/Types.scala4
-rw-r--r--test/files/pos/t8301.scala19
2 files changed, 21 insertions, 2 deletions
diff --git a/src/reflect/scala/reflect/internal/Types.scala b/src/reflect/scala/reflect/internal/Types.scala
index d60ea73814..ac6c6f67c0 100644
--- a/src/reflect/scala/reflect/internal/Types.scala
+++ b/src/reflect/scala/reflect/internal/Types.scala
@@ -4133,8 +4133,8 @@ trait Types
if (symHi.isTerm)
(isSubType(tpLo, tpHi, depth) &&
- (!symHi.isStable || symLo.isStable) && // sub-member must remain stable
- (!symLo.hasVolatileType || symHi.hasVolatileType)) // sub-member must not introduce volatility
+ (!symHi.isStable || symLo.isStable) && // sub-member must remain stable
+ (!symLo.hasVolatileType || symHi.hasVolatileType || tpHi.isWildcard)) // sub-member must not introduce volatility
else if (symHi.isAbstractType)
((tpHi.bounds containsType tpLo) &&
kindsConform(symHi :: Nil, tpLo :: Nil, preLo, symLo.owner))
diff --git a/test/files/pos/t8301.scala b/test/files/pos/t8301.scala
new file mode 100644
index 0000000000..2d10864c57
--- /dev/null
+++ b/test/files/pos/t8301.scala
@@ -0,0 +1,19 @@
+trait Universe {
+ type Symbol >: Null <: AnyRef with SymbolApi
+ trait SymbolApi
+
+ type TypeSymbol >: Null <: TypeSymbolApi with Symbol
+ trait TypeSymbolApi
+
+ implicit class CompatibleSymbol(sym: Symbol) {
+ def asFreeType: TypeSymbol = ???
+ }
+}
+
+object Test extends App {
+ val u: Universe = ???
+ import u._
+
+ val sym: Symbol = ???
+ sym.asFreeType
+}