@@ -189,7 +189,7 @@ class SyntheticMembers(thisPhase: DenotTransformer) {
189189 * def productElement(index: Int): Any = index match {
190190 * case 0 => this._1
191191 * case 1 => this._2
192- * case _ => throw new IndexOutOfBoundsException(index.toString )
192+ * case _ => throw new IndexOutOfBoundsException(index)
193193 * }
194194 * ```
195195 */
@@ -215,7 +215,7 @@ class SyntheticMembers(thisPhase: DenotTransformer) {
215215 * def productElement(index: Int): Any = index match {
216216 * case 0 => this.x
217217 * case 1 => this.y
218- * case _ => throw new IndexOutOfBoundsException(index.toString )
218+ * case _ => throw new IndexOutOfBoundsException(index)
219219 * }
220220 * ```
221221 */
@@ -242,7 +242,7 @@ class SyntheticMembers(thisPhase: DenotTransformer) {
242242 * def productElementName(index: Int): String = index match {
243243 * case 0 => "x"
244244 * case 1 => "y"
245- * case _ => throw new IndexOutOfBoundsException(index.toString )
245+ * case _ => throw new IndexOutOfBoundsException(index)
246246 * }
247247 * ```
248248 */
@@ -255,20 +255,16 @@ class SyntheticMembers(thisPhase: DenotTransformer) {
255255 Match (index, (cases :+ generateIOBECase(index)).toList)
256256 }
257257
258+ /** Generate a tree equivalent to the following source level code:
259+ * ```scala
260+ * case _: Int => throw new IndexOutOfBoundsException(index)
261+ * ```
262+ */
258263 def generateIOBECase (index : Tree ): CaseDef = {
259- val ioob = defn.IndexOutOfBoundsException .typeRef
260- // Second constructor of ioob that takes a String argument
261- def filterStringConstructor (s : Symbol ): Boolean = s.info match {
262- case m : MethodType if s.isConstructor && m.paramInfos.size == 1 =>
263- m.paramInfos.head.stripNull() == defn.StringType
264- case _ => false
265- }
266- val constructor = ioob.typeSymbol.info.decls.find(filterStringConstructor(_)).asTerm
267- val stringIndex = Apply (Select (index, nme.toString_), Nil )
268- val error = Throw (New (ioob, constructor, List (stringIndex)))
269-
270- // case _ => throw new IndexOutOfBoundsException(i.toString)
271- CaseDef (Underscore (defn.IntType ), EmptyTree , error)
264+ val rhs = New (defn.IndexOutOfBoundsExceptionType )
265+ .select(defn.IndexOutOfBoundsException_IntConstructor )
266+ .appliedTo(index)
267+ CaseDef (Underscore (defn.IntType ), EmptyTree , Throw (rhs))
272268 }
273269
274270 /** The class
0 commit comments