File tree 2 files changed +17
-1
lines changed
compiler/src/dotty/tools/dotc/transform
2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -158,11 +158,13 @@ object TypeTestsCasts {
158
158
val methodSymbol = sym.owner
159
159
val tpSyms = typer.ErrorReporting .substitutableTypeSymbolsInScope(sym).toSet
160
160
def isAccessible (sym : Symbol ): Boolean = sym == methodSymbol || sym.isType && isAccessible(sym.owner)
161
+ val seen = scala.collection.mutable.Set .empty[Type ]
161
162
def hasPoison (tp : Type ): Boolean =
163
+ seen += tp
162
164
tp.baseClasses.filter(isAccessible).exists { sym =>
163
165
sym.info.decls.exists { sym =>
164
166
sym.info.existsPart(tp => tpSyms.contains(tp.typeSymbol))
165
- || isAccessible(sym.info.typeSymbol.maybeOwner) && hasPoison(sym.info)
167
+ || ! seen.contains(sym.info) && isAccessible(sym.info.typeSymbol.maybeOwner) && hasPoison(sym.info)
166
168
}
167
169
}
168
170
! hasPoison(tp2)
Original file line number Diff line number Diff line change @@ -53,6 +53,20 @@ object Test:
53
53
prev = new A (x)
54
54
x
55
55
56
+ def test6 [T ](x : T ): T =
57
+ class Foo { var bar : Bar = null }
58
+ class Bar { var foo : Foo = null ; var elem : T = _ }
59
+ prev match
60
+ case prev : Foo => // error: the type test for A cannot be checked at runtime
61
+ prev.bar.elem
62
+ case _ =>
63
+ val foo = new Foo
64
+ val bar = new Bar
65
+ bar.elem = x
66
+ foo.bar = bar
67
+ prev = foo
68
+ x
69
+
56
70
def main (args : Array [String ]): Unit =
57
71
test(1 )
58
72
val x : String = test(" " ) // was: ClassCastException: java.lang.Integer cannot be cast to java.lang.String
You can’t perform that action at this time.
0 commit comments