Skip to content

Commit

Permalink
Merge pull request #464 from ShaneDelmore/456
Browse files Browse the repository at this point in the history
fix ascription when extending from non-polymorphic trait with polymor…
  • Loading branch information
Shane Delmore committed Jul 30, 2019
2 parents 471f698 + bcc9e0a commit 987fa54
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
20 changes: 20 additions & 0 deletions scalafix/input/src/main/scala/rsc/tests/BetterRscCompat.scala
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
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
}
}
11 changes: 9 additions & 2 deletions scalafix/rules/src/main/scala/rsc/rules/RscCompat.scala
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,14 @@ 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])) {
//TODO getOrElse is a workaround for a bug in semanticdb that may cause symbols to
//be incorrect in some cases https://github.com/scalameta/scalameta/issues/1887
lazy val isTrait = (for {
symbol <- init.symbol
info <- symbols.info(symbol.syntax)
} yield info.kind == Kind.TRAIT).getOrElse(false)
// 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 987fa54

Please sign in to comment.