Skip to content

Commit a575f9c

Browse files
authored
Merge pull request #10664 from dotty-staging/warn-opaque-match
Warn when matching against an opaque type
2 parents 3cc191b + 5a6542b commit a575f9c

File tree

4 files changed

+32
-5
lines changed

4 files changed

+32
-5
lines changed

compiler/src/dotty/tools/dotc/core/unpickleScala2/PickleBuffer.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,10 +241,10 @@ object PickleBuffer {
241241
val termMap, typeMap = new Array[Long](64)
242242
for (idx <- 0 until ScalaFlagEnd)
243243
corr get (1L << idx) match {
244-
case Some((termFlag: FlagSet, typeFlag: FlagSet)) =>
244+
case Some((termFlag: FlagSet @unchecked, typeFlag: FlagSet @unchecked)) =>
245245
termMap(idx) |= termFlag.bits
246246
typeMap(idx) |= typeFlag.bits
247-
case Some(commonFlag: FlagSet) =>
247+
case Some(commonFlag: FlagSet @unchecked) =>
248248
termMap(idx) |= commonFlag.toTermFlags.bits
249249
typeMap(idx) |= commonFlag.toTypeFlags.bits
250250
case _ =>

compiler/src/dotty/tools/dotc/transform/TypeTestsCasts.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ object TypeTestsCasts {
5353
* 7. if `P` is a refinement type, FALSE
5454
* 8. otherwise, TRUE
5555
*/
56-
def checkable(X: Type, P: Type, span: Span)(using Context): Boolean = {
56+
def checkable(X: Type, P: Type, span: Span)(using Context): Boolean = atPhase(Phases.refchecksPhase.next) {
57+
// Run just before ElimOpaque transform (which follows RefChecks)
5758
def isAbstract(P: Type) = !P.dealias.typeSymbol.isClass
5859

5960
def replaceP(tp: Type)(using Context) = new TypeMap {
@@ -71,7 +72,7 @@ object TypeTestsCasts {
7172
case tref: TypeRef if tref.typeSymbol.isPatternBound =>
7273
if (variance == 1) tref.info.hiBound
7374
else if (variance == -1) tref.info.loBound
74-
else OrType(defn.AnyType, defn.NothingType, soft = true)
75+
else OrType(defn.AnyType, defn.NothingType, soft = true) // TODO: what does this line do?
7576
case _ => mapOver(tp)
7677
}
7778
}.apply(tp)

library/src/scala/Tuple.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ object Tuple {
216216
/** Convert an immutable array into a tuple of unknown arity and types */
217217
def fromIArray[T](xs: IArray[T]): Tuple = {
218218
val xs2: IArray[Object] = xs match {
219-
case xs: IArray[Object] => xs
219+
case xs: IArray[Object] @unchecked => xs
220220
case xs =>
221221
// TODO support IArray.map
222222
xs.asInstanceOf[Array[T]].map(_.asInstanceOf[Object]).asInstanceOf[IArray[Object]]
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
case class C()
2+
3+
object O:
4+
opaque type T <: C = C
5+
val x: T = C()
6+
(??? : Any) match
7+
case _: T => ??? // OK
8+
9+
def Test[T] =
10+
O.x match
11+
case _: C => ??? // ok
12+
C() match
13+
case _: O.T => ??? // error
14+
C() match
15+
case _: T => ??? // error
16+
17+
(??? : Any) match
18+
case _: List[O.T] => ??? // error
19+
(??? : Any) match
20+
case _: List[O.T @unchecked] => ??? // OK
21+
(??? : Any) match
22+
case _: List[T] => ??? // error
23+
24+
25+
26+

0 commit comments

Comments
 (0)