Skip to content

Commit

Permalink
fix ascription when extending from non-polymorphic trait with polymor…
Browse files Browse the repository at this point in the history
…phic grandparent class (fix #456)
  • Loading branch information
Shane Delmore committed Jul 29, 2019
1 parent 97637a9 commit ab32e2c
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
20 changes: 20 additions & 0 deletions scalafix/input/src/main/scala/rsc/tests/BetterRscCompat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -263,4 +263,24 @@ object BetterRscCompat_Test {
object NestedTuples {
val foo = (("1", 1), 1.0)
}

object PolymorphicGrandparent {
class C[A]

abstract class D[A]

trait E[A]

trait T extends C[Int]

trait U extends D[Int]

trait V extends E[Int]

class F extends T

class G extends U

class H extends V
}
}
20 changes: 20 additions & 0 deletions scalafix/output/src/main/scala/rsc/tests/BetterRscCompat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -263,4 +263,24 @@ object BetterRscCompat_Test {
object NestedTuples {
val foo: ((String, Int), Double) = (("1", 1), 1.0)
}

object PolymorphicGrandparent {
class C[A]

abstract class D[A]

trait E[A]

trait T extends C[Int]

trait U extends D[Int]

trait V extends E[Int]

class F extends T

class G extends U

class H extends V
}
}
9 changes: 7 additions & 2 deletions scalafix/rules/src/main/scala/rsc/rules/RscCompat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import scala.meta.internal.{semanticdb => s}
import scala.meta.internal.semanticdb.Scala._
import scala.meta.internal.semanticdb.Scala.{Names => n}
import scala.meta.internal.semanticdb.Scala.{Descriptor => d}
import scala.meta.internal.semanticdb.SymbolInformation.Kind
import scalafix.internal.v0._
import scalafix.syntax._
import scalafix.util.TokenOps
Expand Down Expand Up @@ -129,8 +130,12 @@ case class RscCompat(legacyIndex: SemanticdbIndex, config: RscCompatConfig)
val name = templ.name.get
inits.headOption.foreach { init =>
val tokens = init.tpe.tokens
// If type params of init may be inferred
if (!tokens.exists(_.is[Token.LeftBracket])) {
lazy val isTrait = (for {
symbol <- init.symbol
info <- symbols.info(symbol.syntax)
} yield info.kind == Kind.TRAIT).get
// If type params of init may be inferred and init is not a trait
if (!tokens.exists(_.is[Token.LeftBracket]) && !isTrait) {
buf += RewriteInit(env, name, tokens.last)
}
}
Expand Down

0 comments on commit ab32e2c

Please sign in to comment.