Skip to content

Commit 8e7ef94

Browse files
committed
TypeAssigner: fix return type of clone() for arrays
Given the following code: val x: Array[String] = new Array[String](1) x(0) = "foo" println(x.clone().apply(0)) Before this commit, the last line was rewritten in Erasure to: println(x.clone().[]apply(0)) This is incorrect: clone() returns an Object, so a cast is necessary, this resulted in the following failure at runtime: java.lang.VerifyError: Bad type on operand stack in aaload After this commit, the last line is rewritten in Erasure to: println(x.clone().asInstanceOf[String[]].[]apply(0)) This corresponds to adding a "checkcast" instruction in the generated bytecode, and is enough to fix the runtime error.
1 parent 1e9c012 commit 8e7ef94

File tree

1 file changed

+0
-1
lines changed

1 file changed

+0
-1
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,6 @@ 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)
214213
case _ => accessibleSelectionType(tree, qual)
215214
}
216215
tree.withType(tp)

0 commit comments

Comments
 (0)