Skip to content

Commit d55b719

Browse files
committed
Merge pull request #501 from smarter/fix/arrayClone
TypeAssigner: fix return type of clone() for arrays
2 parents 9ba09d4 + 96d7531 commit d55b719

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,13 @@ trait TypeAssigner {
210210
case p.arrayApply => MethodType(defn.IntType :: Nil, arrayElemType)
211211
case p.arrayUpdate => MethodType(defn.IntType :: arrayElemType :: Nil, defn.UnitType)
212212
case p.arrayLength => MethodType(Nil, defn.IntType)
213-
case nme.clone_ if qualType.isInstanceOf[JavaArrayType] => MethodType(Nil, qualType)
213+
214+
// Note that we do not need to handle calls to Array[T]#clone() specially:
215+
// The JLS section 10.7 says "The return type of the clone method of an array type
216+
// T[] is T[]", but the actual return type at the bytecode level is Object which
217+
// is casted to T[] by javac. Since the return type of Array[T]#clone() is Array[T],
218+
// this is exactly what Erasure will do.
219+
214220
case _ => accessibleSelectionType(tree, qual)
215221
}
216222
tree.withType(tp)

0 commit comments

Comments
 (0)