Skip to content

Commit fd49b1d

Browse files
committed
Check arrays uptate and length
1 parent 959c397 commit fd49b1d

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ trait TypeAssigner {
282282
val tp = tree.name match {
283283
case p.arrayApply => MethodType(defn.IntType :: Nil, arrayElemType)
284284
case p.arrayUpdate => MethodType(defn.IntType :: arrayElemType :: Nil, defn.UnitType)
285-
case p.arrayLength => MethodType(Nil, defn.IntType)
285+
case p.arrayLength => arrayElemType; MethodType(Nil, defn.IntType)
286286

287287
// Note that we do not need to handle calls to Array[T]#clone() specially:
288288
// The JLS section 10.7 says "The return type of the clone method of an array type

tests/neg/i4247b.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+
self(0) = ??? // error: Array type conflict with Foo
3+
}

tests/neg/i4247c.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+
self.length // error: Array type conflict with Foo
3+
}

0 commit comments

Comments
 (0)