Skip to content

Commit 959c397

Browse files
committed
Fix scala#4247: Do not crash if self is of Array type
1 parent 4c8a2bd commit 959c397

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,12 @@ trait TypeAssigner {
271271
def assignType(tree: untpd.Select, qual: Tree)(implicit ctx: Context): Select = {
272272
def qualType = qual.tpe.widen
273273
def arrayElemType = {
274-
val JavaArrayType(elemtp) = qualType
275-
elemtp
274+
qualType match {
275+
case JavaArrayType(elemtp) => elemtp
276+
case _ =>
277+
ctx.error("Array type conflict with " + qual.symbol.name, tree.pos)
278+
defn.NothingType
279+
}
276280
}
277281
val p = nme.primitive
278282
val tp = tree.name match {

tests/neg/i4247.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Foo[U] { self : Array[U] & Nothing =>
2+
val s = self(0) // error: Array type conflict with Foo
3+
}

0 commit comments

Comments
 (0)