File tree 2 files changed +21
-5
lines changed
compiler/src/dotty/tools/dotc/transform
2 files changed +21
-5
lines changed Original file line number Diff line number Diff line change @@ -243,11 +243,8 @@ object TypeTestsCasts {
243
243
else foundClasses.exists(check)
244
244
end checkSensical
245
245
246
- if (expr.tpe <:< testType)
247
- if (expr.tpe.isNotNull) {
248
- if (! inMatch) report.warning(TypeTestAlwaysSucceeds (expr.tpe, testType), tree.srcPos)
249
- constant(expr, Literal (Constant (true )))
250
- }
246
+ if (expr.tpe <:< testType) && inMatch then
247
+ if expr.tpe.isNotNull then constant(expr, Literal (Constant (true )))
251
248
else expr.testNotNull
252
249
else {
253
250
val nestedCtx = ctx.fresh.setNewTyperState()
Original file line number Diff line number Diff line change
1
+ trait Fruit
2
+ case class Apple () extends Fruit
3
+ case class Orange () extends Fruit
4
+
5
+ case class Box [C ](fruit : C ) extends Fruit
6
+
7
+ val apple = Box (fruit = Apple ())
8
+ val orange = Box (fruit = Orange ())
9
+
10
+
11
+ val result = List (apple, orange).map {
12
+ case appleBox : Box [Apple ] @ unchecked if appleBox.fruit.isInstanceOf [Apple ] => // contains apple
13
+ " apple"
14
+ case _ =>
15
+ " orange"
16
+ }
17
+
18
+ @ main def Test =
19
+ assert(result == List (" apple" , " orange" ))
You can’t perform that action at this time.
0 commit comments