Skip to content

Commit c7de6a4

Browse files
Select ioob constructor by type instead of position in declarations
1 parent df39a40 commit c7de6a4

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

compiler/src/dotty/tools/dotc/transform/SyntheticMethods.scala

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,12 @@ class SyntheticMethods(thisTransformer: DenotTransformer) {
116116
*/
117117
def productElementBody(arity: Int, index: Tree)(implicit ctx: Context): Tree = {
118118
val ioob = defn.IndexOutOfBoundsException.typeRef
119-
// That's not ioob.typeSymbol.primaryConstructor, this is the other one
120-
// that takes a String argument.
121-
val constructor = ioob.typeSymbol.info.decls.toList.tail.head.asTerm
119+
// Second constructor of ioob that takes a String argument
120+
def filterStringConstructor(s: Symbol): Boolean = s.info match {
121+
case m: MethodType if s.isConstructor => m.paramInfos == List(defn.StringType)
122+
case _ => false
123+
}
124+
val constructor = ioob.typeSymbol.info.decls.find(filterStringConstructor _).asTerm
122125
val stringIndex = Apply(Select(index, nme.toString_), Nil)
123126
val error = Throw(New(ioob, constructor, List(stringIndex)))
124127

0 commit comments

Comments
 (0)