merged fix from Guillem Salas for bug https://issues.scala-lang.org/browse/SI-4267