Skip to content

Commit 377b479

Browse files
committed
Fix #4247: Handle Array self types
1 parent 7a99d3d commit 377b479

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

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

+6-2
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,12 @@ trait TypeAssigner {
315315
def assignType(tree: untpd.Select, qual: Tree)(implicit ctx: Context): Select = {
316316
def qualType = qual.tpe.widen
317317
def arrayElemType = {
318-
val JavaArrayType(elemtp) = qualType
319-
elemtp
318+
qualType match {
319+
case JavaArrayType(elemtp) => elemtp
320+
case _ =>
321+
ctx.error("Expected Array but was " + qualType.show, tree.sourcePos)
322+
defn.NothingType
323+
}
320324
}
321325
val p = nme.primitive
322326
val tp = tree.name match {

tests/neg/i4247.scala

+3
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
3+
}

tests/neg/i4247b.scala

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Foo[U] { self : Array[U] =>
2+
self(0) // error
3+
}

0 commit comments

Comments
 (0)