Skip to content

Commit 3324397

Browse files
committed
Try harder to avoid generating ClassTags for Nothing/Null subtypes
`typeSymbol` returns NoSymbol on an intersection type, so our previous check wasn't good enough. See #1730 for background.
1 parent 4a3747a commit 3324397

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

compiler/src/dotty/tools/dotc/typer/Synthesizer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class Synthesizer(typer: Typer)(using @constructorOnly c: Context):
3434
case defn.ArrayOf(elemTp) =>
3535
val etag = typer.inferImplicitArg(defn.ClassTagClass.typeRef.appliedTo(elemTp), span)
3636
if etag.tpe.isError then EmptyTree else etag.select(nme.wrap)
37-
case tp if hasStableErasure(tp) && !defn.isBottomClassAfterErasure(tp.typeSymbol) =>
37+
case tp if hasStableErasure(tp) && !tp.isBottomTypeAfterErasure =>
3838
val sym = tp.typeSymbol
3939
val classTagModul = ref(defn.ClassTagModule)
4040
if defn.SpecialClassTagClasses.contains(sym) then

tests/neg/i1730.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import scala.reflect.ClassTag
2+
3+
@main def Test =
4+
val x: Array[? <: String] = Array[Int & Nothing]() // error: No ClassTag available for Int & Nothing
5+
// (was: ClassCastException: [I cannot be cast to [Ljava.lang.String)
6+
val y: Array[? <: Int] = Array[String & Nothing]() // error: No ClassTag available for String & Nothing
7+
// (was: ClassCastException: [Lscala.runtime.Nothing$; cannot be cast to [I)

0 commit comments

Comments
 (0)