diff --git a/docs/developers/tutorial.md b/docs/developers/tutorial.md index 9c41e9546f..2dcd813158 100644 --- a/docs/developers/tutorial.md +++ b/docs/developers/tutorial.md @@ -181,7 +181,7 @@ To fix this bug, we first match function call nodes `Term.Apply` and pattern match only `Lit.Boolean` that appear in argument position ```scala -case Term.Apply(_, args) => +case Term.Apply.After_4_6_0(_, args) => args.collect { case t @ Lit.Boolean(_) => Patch.addLeft(t, "isSuccess = ") @@ -206,8 +206,8 @@ is to produce `finish(isError = true)`. To fix this bug, we start by capturing the called method into a variable `fun` ```diff -- case Term.Apply(_, args) => -+ case Term.Apply(fun, args) => +- case Term.Apply.After_4_6_0(_, args) => ++ case Term.Apply.After_4_6_0(fun, args) => ``` We update the call to `args.collect` to include the index of the argument @@ -284,7 +284,7 @@ class NamedLiteralArguments extends SemanticRule("NamedLiteralArguments") { override def fix(implicit doc: SemanticDocument): Patch = { doc.tree.collect { - case Term.Apply(fun, args) => + case Term.Apply.After_4_6_0(fun, args) => args.zipWithIndex.collect { case (t @ Lit.Boolean(_), i) => fun.symbol.info match { @@ -384,7 +384,7 @@ Next, we write the same pattern matching logic as in `NamedLiteralArguments` ```scala doc.tree.collect { - case Term.Apply(_, args) => + case Term.Apply.After_4_6_0(_, args) => args.collect { case t @ Lit.Boolean(_) => // .... @@ -581,7 +581,7 @@ class NoLiteralArguments(config: NoLiteralArgumentsConfig) override def fix(implicit doc: SyntacticDocument): Patch = { doc.tree .collect { - case Term.Apply(_, args) => + case Term.Apply.After_4_6_0(_, args) => args.collect { case t: Lit if config.isDisabled(t) => Patch.lint(LiteralArgument(t)) diff --git a/project/ScalafixBuild.scala b/project/ScalafixBuild.scala index ff82e4a446..6b84f14a57 100644 --- a/project/ScalafixBuild.scala +++ b/project/ScalafixBuild.scala @@ -86,7 +86,8 @@ object ScalafixBuild extends AutoPlugin with GhpagesKeys { "-encoding", "UTF-8", "-feature", - "-unchecked" + "-unchecked", + "-Wconf:cat=deprecation&origin=scala\\.meta\\..*:error", ) ) diff --git a/scalafix-core/src/main/scala/scalafix/internal/patch/EscapeHatch.scala b/scalafix-core/src/main/scala/scalafix/internal/patch/EscapeHatch.scala index d940db3d34..f33212ce34 100644 --- a/scalafix-core/src/main/scala/scalafix/internal/patch/EscapeHatch.scala +++ b/scalafix-core/src/main/scala/scalafix/internal/patch/EscapeHatch.scala @@ -242,19 +242,39 @@ object EscapeHatch { def unapply(mods: List[Mod]): Option[List[Term]] = mods.collectFirst { case Mod.Annot( - Init( + Init.After_4_6_0( Type.Name(SuppressWarnings), _, - List(Term.Apply(Term.Name("Array"), args) :: Nil) + List( + Term.ArgClause( + List( + Term.Apply.After_4_6_0( + Term.Name("Array"), + Term.ArgClause(args, None) + ) + ), + None + ) + ) ) ) => args case Mod.Annot( - Init( + Init.After_4_6_0( Type.Select(_, Type.Name(SuppressWarnings)), _, - List(Term.Apply(Term.Name("Array"), args) :: Nil) + List( + Term.ArgClause( + List( + Term.Apply.After_4_6_0( + Term.Name("Array"), + Term.ArgClause(args, None) + ) + ), + None + ) + ) ) ) => args diff --git a/scalafix-core/src/main/scala/scalafix/internal/patch/ReplaceSymbolOps.scala b/scalafix-core/src/main/scala/scalafix/internal/patch/ReplaceSymbolOps.scala index bdc10bb790..27972205bf 100644 --- a/scalafix-core/src/main/scala/scalafix/internal/patch/ReplaceSymbolOps.scala +++ b/scalafix-core/src/main/scala/scalafix/internal/patch/ReplaceSymbolOps.scala @@ -88,7 +88,7 @@ object ReplaceSymbolOps { object Identifier { def unapply(tree: Tree): Option[(Name, Symbol)] = tree match { case n: Name => n.symbol.map(s => n -> s) - case Init(n: Name, _, _) => n.symbol.map(s => n -> s) + case Init.After_4_6_0(n: Name, _, _) => n.symbol.map(s => n -> s) case _ => None } } diff --git a/scalafix-core/src/main/scala/scalafix/internal/util/DenotationOps.scala b/scalafix-core/src/main/scala/scalafix/internal/util/DenotationOps.scala index acdf756c14..d012363244 100644 --- a/scalafix-core/src/main/scala/scalafix/internal/util/DenotationOps.scala +++ b/scalafix-core/src/main/scala/scalafix/internal/util/DenotationOps.scala @@ -7,7 +7,7 @@ import scalafix.v0._ object DenotationOps { val defaultDialect: Dialect = - dialects.Scala212.copy(allowTypeLambdas = true) + dialects.Scala212.withAllowTypeLambdas(true) def resultType( symbol: Symbol, @@ -15,9 +15,9 @@ object DenotationOps { dialect: Dialect ): Option[Type] = { def getDeclType(tpe: Type): Type = tpe match { - case Type.Method(_, tpe) if denot.isMethod => tpe - case Type.Lambda(_, tpe) if denot.isMethod => getDeclType(tpe) - case Type.Method((Term.Param(_, _, Some(tpe), _) :: Nil) :: Nil, _) + case Type.Method.After_4_6_0(_, tpe) if denot.isMethod => tpe + case Type.Lambda.After_4_6_0(_, tpe) if denot.isMethod => getDeclType(tpe) + case Type.Method.After_4_6_0(Term.ParamClause(Term.Param(_, _, Some(tpe), _) :: Nil, None) :: Nil, _) if denot.isVar => // Workaround for https://github.com/scalameta/scalameta/issues/1100 tpe diff --git a/scalafix-core/src/main/scala/scalafix/internal/util/PrettyType.scala b/scalafix-core/src/main/scala/scalafix/internal/util/PrettyType.scala index 7672108b3d..2005bb9fd3 100644 --- a/scalafix-core/src/main/scala/scalafix/internal/util/PrettyType.scala +++ b/scalafix-core/src/main/scala/scalafix/internal/util/PrettyType.scala @@ -216,17 +216,21 @@ class PrettyType private ( toMods(info), Name(""), paramss.iterator - .map(params => params.symbols.smap(toTermParam)) + .map(params => Term.ParamClause(params.symbols.smap(toTermParam))) .toList ) } else { Decl.Def( toMods(info), Term.Name(info.displayName), - tparams.smap(toTypeParam), - paramss.iterator - .map(params => params.symbols.smap(toTermParam)) - .toList, + List( + Member.ParamClauseGroup( + tparams.smap(toTypeParam), + paramss.iterator + .map(params => Term.ParamClause(params.symbols.smap(toTermParam))) + .toList, + ) + ), toType(ret) ) } @@ -267,7 +271,7 @@ class PrettyType private ( Defn.Trait( toMods(info), Type.Name(info.displayName), - tparams.smap(toTypeParam), + Type.ParamClause(tparams.smap(toTypeParam)), Ctor.Primary(Nil, Name(""), Seq.empty[Term.ParamClause]), Template( Nil, @@ -279,7 +283,8 @@ class PrettyType private ( !i.isVarSetter ) toStat(i) else Nil - } + }, + Nil ) ) case k.OBJECT => @@ -290,7 +295,8 @@ class PrettyType private ( Nil, inits, Self(Name(""), None), - objectDecls + objectDecls, + Nil ) ) case k.PACKAGE_OBJECT => @@ -301,7 +307,8 @@ class PrettyType private ( Nil, inits, Self(Name(""), None), - objectDecls + objectDecls, + Nil ) ) case k.CLASS => @@ -309,7 +316,7 @@ class PrettyType private ( .collectFirst { case i if i.kind.isConstructor && i.is(p.PRIMARY) => toTree(i) match { - case ctor @ Ctor.Primary(_, _, Nil :: Nil) + case ctor @ Ctor.Primary.After_4_6_0(_, _, Nil :: Nil) if !info.is(p.CASE) => // Remove redudant () for non-case classes: class Foo ctor.copy(paramss = Nil) @@ -317,11 +324,11 @@ class PrettyType private ( } } .getOrElse { - Ctor.Primary(Nil, Name(""), Seq.empty[Term.ParamClause]) + Ctor.Primary.After_4_6_0(Nil, Name(""), Seq.empty[Term.ParamClause]) } // FIXME: Workaround for https://github.com/scalameta/scalameta/issues/1492 - val isCtorName = ctor.paramss.flatMap(_.map(_.name.value)).toSet + val isCtorName = ctor.paramClauses.flatMap(_.values).map(_.name.value).toSet def isSyntheticMember(m: s.SymbolInformation): Boolean = (isCaseClass && isCaseClassMethod(m.displayName)) || isCtorName(m.displayName) @@ -329,7 +336,7 @@ class PrettyType private ( Defn.Class( toMods(info), Type.Name(info.displayName), - tparams.smap(toTypeParam), + Type.ParamClause(tparams.smap(toTypeParam)), ctor, Template( Nil, @@ -342,7 +349,8 @@ class PrettyType private ( !isSyntheticMember(i) ) toStat(i) else Nil - } + }, + Nil ) ) case _ => @@ -353,14 +361,14 @@ class PrettyType private ( Defn.Type( toMods(info), Type.Name(info.displayName), - typeParameters.smap(toTypeParam), + Type.ParamClause(typeParameters.smap(toTypeParam)), toType(lo) ) } else { Decl.Type( toMods(info), Type.Name(info.displayName), - typeParameters.smap(toTypeParam), + Type.ParamClause(typeParameters.smap(toTypeParam)), toTypeBounds(lo, hi) ) } @@ -389,7 +397,7 @@ class PrettyType private ( case _ => tpe } - Init( + Init.After_4_6_0( toType(fixed), Name.Anonymous(), // Can't support term arguments @@ -518,14 +526,14 @@ class PrettyType private ( def targs: List[Type] = typeArguments.iterator.map { case TypeExtractors.Wildcard() => - Type.Placeholder(Type.Bounds(None, None)) + Type.Wildcard(Type.Bounds(None, None)) case targ => toType(targ) }.toList symbol match { case TypeExtractors.FunctionN() if typeArguments.lengthCompare(0) > 0 => val params :+ res = targs - Type.Function(params, res) + Type.Function(Type.FuncParamClause(params), res) case TypeExtractors.TupleN() if typeArguments.lengthCompare(1) > 0 => Type.Tuple(targs) case _ => @@ -548,7 +556,7 @@ class PrettyType private ( case (name: Type.Name, Seq(lhs, rhs)) if !Character.isJavaIdentifierPart(name.value.head) => Type.ApplyInfix(lhs, name, rhs) - case (q, targs) => Type.Apply(q, targs) + case (q, targs) => Type.Apply(q, Type.ArgClause(targs)) } } case s.SingleType(_, symbol) => @@ -634,7 +642,7 @@ class PrettyType private ( Defn.Type( Nil, universalName, - typeParameters.smap(toTypeParam), + Type.ParamClause(typeParameters.smap(toTypeParam)), toType(underlying) ) :: Nil ), @@ -681,7 +689,7 @@ class PrettyType private ( Type.Param( Nil, Name(""), - Nil, + Type.ParamClause(Nil), Type.Bounds(None, None), Nil, Nil @@ -698,7 +706,7 @@ class PrettyType private ( Type.Param( toMods(info), name = Type.Name(info.displayName), - tparams = tparams, + tparamClause = Type.ParamClause(tparams), tbounds = bounds, // TODO: re-sugar context and view bounds https://github.com/scalacenter/scalafix/issues/759 vbounds = Nil, diff --git a/scalafix-core/src/main/scala/scalafix/internal/v1/PositionSearch.scala b/scalafix-core/src/main/scala/scalafix/internal/v1/PositionSearch.scala index 9d69ec0f40..3060ad6aff 100644 --- a/scalafix-core/src/main/scala/scalafix/internal/v1/PositionSearch.scala +++ b/scalafix-core/src/main/scala/scalafix/internal/v1/PositionSearch.scala @@ -9,7 +9,7 @@ import scalafix.internal.util.PositionSyntax._ object PositionSearch { def find(tree: Tree, pos: Position): Option[Tree] = { val extrapos = tree match { - case Term.ApplyInfix(lhs, op, Nil, _) => + case Term.ApplyInfix.After_4_6_0(lhs, op, Nil, _) => List(Position.Range(lhs.pos.input, lhs.pos.start, op.pos.end)) case _ => List() diff --git a/scalafix-core/src/main/scala/scalafix/internal/v1/TreePos.scala b/scalafix-core/src/main/scala/scalafix/internal/v1/TreePos.scala index 7a78114761..cfe7db165b 100644 --- a/scalafix-core/src/main/scala/scalafix/internal/v1/TreePos.scala +++ b/scalafix-core/src/main/scala/scalafix/internal/v1/TreePos.scala @@ -61,7 +61,7 @@ object TreePos { case t: Pat.Interpolate => symbolImpl(t.prefix) case Defn.Val(_, p :: Nil, _, _) => symbolImpl(p) case Decl.Val(_, p :: Nil, _) => symbolImpl(p) - case Defn.Var(_, p :: Nil, _, _) => symbolImpl(p) + case Defn.Var.After_4_7_2(_, p :: Nil, _, _) => symbolImpl(p) case Decl.Var(_, p :: Nil, _) => symbolImpl(p) case t: Importee.Rename => symbolImpl(t.name) case t: Importee.Name => symbolImpl(t.name) diff --git a/scalafix-core/src/main/scala/scalafix/util/TreeOps.scala b/scalafix-core/src/main/scala/scalafix/util/TreeOps.scala index a4c8ce1cc6..7f8401965d 100644 --- a/scalafix-core/src/main/scala/scalafix/util/TreeOps.scala +++ b/scalafix-core/src/main/scala/scalafix/util/TreeOps.scala @@ -24,23 +24,23 @@ object TreeExtractors { object Mods { def unapply(tree: Tree): Option[List[Mod]] = tree match { - case Ctor.Primary(mods, _, _) => Some(mods) - case Ctor.Secondary(mods, _, _, _, _) => Some(mods) - case Decl.Def(mods, _, _, _, _) => Some(mods) - case Decl.Type(mods, _, _, _) => Some(mods) + case Ctor.Primary.After_4_6_0(mods, _, _) => Some(mods) + case Ctor.Secondary.After_4_6_0(mods, _, _, _, _) => Some(mods) + case Decl.Def.After_4_6_0(mods, _, _, _) => Some(mods) + case Decl.Type.After_4_6_0(mods, _, _, _) => Some(mods) case Decl.Val(mods, _, _) => Some(mods) case Decl.Var(mods, _, _) => Some(mods) - case Defn.Class(mods, _, _, _, _) => Some(mods) - case Defn.Def(mods, _, _, _, _, _) => Some(mods) - case Defn.Macro(mods, _, _, _, _, _) => Some(mods) + case Defn.Class.After_4_6_0(mods, _, _, _, _) => Some(mods) + case Defn.Def.After_4_7_3(mods, _, _, _, _) => Some(mods) + case Defn.Macro.After_4_7_3(mods, _, _, _, _) => Some(mods) case Defn.Object(mods, _, _) => Some(mods) - case Defn.Trait(mods, _, _, _, _) => Some(mods) - case Defn.Type(mods, _, _, _) => Some(mods) + case Defn.Trait.After_4_6_0(mods, _, _, _, _) => Some(mods) + case Defn.Type.After_4_6_0(mods, _, _, _, _) => Some(mods) case Defn.Val(mods, _, _, _) => Some(mods) - case Defn.Var(mods, _, _, _) => Some(mods) + case Defn.Var.After_4_7_2(mods, _, _, _) => Some(mods) case Pkg.Object(mods, _, _) => Some(mods) case Term.Param(mods, _, _, _) => Some(mods) - case Type.Param(mods, _, _, _, _, _) => Some(mods) + case Type.Param.After_4_6_0(mods, _, _, _, _, _) => Some(mods) case _ => None } } diff --git a/scalafix-reflect/src/main/scala/scalafix/internal/reflect/RuleInstrumentation.scala b/scalafix-reflect/src/main/scala/scalafix/internal/reflect/RuleInstrumentation.scala index 2d5f420a62..248745717e 100644 --- a/scalafix-reflect/src/main/scala/scalafix/internal/reflect/RuleInstrumentation.scala +++ b/scalafix-reflect/src/main/scala/scalafix/internal/reflect/RuleInstrumentation.scala @@ -15,24 +15,24 @@ object RuleInstrumentation { def unapply(templ: Template): Boolean = templ match { // v0 - case Template(_, Init(Type.Name("Rewrite"), _, Nil) :: _, _, _) => true + case Template(_, Init.After_4_6_0(Type.Name("Rewrite"), _, Nil) :: _, _, _) => true case Template( _, - Init(Type.Name("Rule"), _, List(List(_))) :: _, + Init.After_4_6_0(Type.Name("Rule"), _, List(List(_))) :: _, _, _ ) => true case Template( _, - Init(Type.Name("SemanticRewrite"), _, List(List(_))) :: _, + Init.After_4_6_0(Type.Name("SemanticRewrite"), _, List(List(_))) :: _, _, _ ) => true case Template( _, - Init(Type.Name("SemanticRule"), _, List(List(_, _))) :: _, + Init.After_4_6_0(Type.Name("SemanticRule"), _, List(List(_, _))) :: _, _, _ ) => @@ -41,28 +41,28 @@ object RuleInstrumentation { // v1 case Template( _, - Init(Type.Name("SemanticRule"), _, List(List(_))) :: _, + Init.After_4_6_0(Type.Name("SemanticRule"), _, List(List(_))) :: _, _, _ ) => true case Template( _, - Init(Type.Name("v1.SemanticRule"), _, List(List(_))) :: _, + Init.After_4_6_0(Type.Name("v1.SemanticRule"), _, List(List(_))) :: _, _, _ ) => true case Template( _, - Init(Type.Name("SyntacticRule"), _, List(List(_))) :: _, + Init.After_4_6_0(Type.Name("SyntacticRule"), _, List(List(_))) :: _, _, _ ) => true case Template( _, - Init(Type.Name("v1.SyntacticRule"), _, List(List(_))) :: _, + Init.After_4_6_0(Type.Name("v1.SyntacticRule"), _, List(List(_))) :: _, _, _ ) => diff --git a/scalafix-rules/src/main/scala/scalafix/internal/rule/DisableSyntax.scala b/scalafix-rules/src/main/scala/scalafix/internal/rule/DisableSyntax.scala index 4d35ccba73..a85833fe4c 100644 --- a/scalafix-rules/src/main/scala/scalafix/internal/rule/DisableSyntax.scala +++ b/scalafix-rules/src/main/scala/scalafix/internal/rule/DisableSyntax.scala @@ -135,7 +135,7 @@ final class DisableSyntax(config: DisableSyntaxConfig) case Defn.Class(mods, _, _, _, templ) if mods.exists(_.is[Mod.Abstract]) => templ.stats - case Defn.Trait(_, _, _, _, templ) => templ.stats + case Defn.Trait.After_4_6_0(_, _, _, _, templ) => templ.stats case _ => List.empty } val vals = stats.flatMap { @@ -248,13 +248,13 @@ final class DisableSyntax(config: DisableSyntaxConfig) case Term.ApplyInfix(_, t @ Term.Name("=="), _, _) if config.noUniversalEquality => Seq(noUniversalEqualityDiagnostic("==", t)) - case Term.Apply(Term.Select(_, t @ Term.Name("==")), _) + case Term.Apply.After_4_6_0(Term.Select(_, t @ Term.Name("==")), _) if config.noUniversalEquality => Seq(noUniversalEqualityDiagnostic("==", t)) case Term.ApplyInfix(_, t @ Term.Name("!="), _, _) if config.noUniversalEquality => Seq(noUniversalEqualityDiagnostic("!=", t)) - case Term.Apply(Term.Select(_, t @ Term.Name("!=")), _) + case Term.Apply.After_4_6_0(Term.Select(_, t @ Term.Name("!=")), _) if config.noUniversalEquality => Seq(noUniversalEqualityDiagnostic("!=", t)) } diff --git a/scalafix-rules/src/main/scala/scalafix/internal/rule/LeakingImplicitClassVal.scala b/scalafix-rules/src/main/scala/scalafix/internal/rule/LeakingImplicitClassVal.scala index 41e949b6a6..2261b5990b 100644 --- a/scalafix-rules/src/main/scala/scalafix/internal/rule/LeakingImplicitClassVal.scala +++ b/scalafix-rules/src/main/scala/scalafix/internal/rule/LeakingImplicitClassVal.scala @@ -16,8 +16,8 @@ class LeakingImplicitClassVal extends SyntacticRule("LeakingImplicitClassVal") { cMods, _, _, - Ctor.Primary(_, _, (Term.Param(pMods, _, _, _) :: Nil) :: Nil), - Template(_, Init(Type.Name("AnyVal"), _, _) :: Nil, _, _) + Ctor.Primary.After_4_6_0(_, _, (Term.Param(pMods, _, _, _) :: Nil) :: Nil), + Template(_, Init.After_4_6_0(Type.Name("AnyVal"), _, _) :: Nil, _, _) ) if cMods.exists(_.is[Mod.Implicit]) => val optPatch = for { anchorMod <- pMods.find(!_.is[Mod.Annot]) diff --git a/scalafix-tests/integration/src/test/scala-2/scalafix/tests/core/PrettyTypeSuite.scala b/scalafix-tests/integration/src/test/scala-2/scalafix/tests/core/PrettyTypeSuite.scala index ef89d36157..102e482034 100644 --- a/scalafix-tests/integration/src/test/scala-2/scalafix/tests/core/PrettyTypeSuite.scala +++ b/scalafix-tests/integration/src/test/scala-2/scalafix/tests/core/PrettyTypeSuite.scala @@ -42,7 +42,7 @@ class PrettyTypeSuite extends BasePrettyTypeSuite { val m.Source(m.Pkg(_, stats) :: Nil) = source.transform { // Remove bodies from methods like `private def foo: Unit` that can't be abstract. case m.Defn.Def(mods, name, tparams, paramss, Some(decltpe), _) => - m.Decl.Def(mods, name, tparams, paramss, decltpe) + m.Decl.Def.After_4_6_0(mods, name, tparams, paramss, decltpe) } // ignoring Functor[C[_]] because of a regression with scalac 2.13.7, see https://github.com/scalacenter/scalafix/pull/1493