Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .scala-steward.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
updates.pin = [
{groupId = "com.typesafe.akka", version = "2.6."},
{groupId = "org.scala-lang", artifactId = "scala3-library", version = "3.3."},
{groupId = "org.scala-lang", artifactId = "scala3-library_sjs1", version = "3.3."},
{groupId = "org.scala-lang", artifactId = "scala3-library", version = "3.9."},
{groupId = "org.scala-lang", artifactId = "scala3-library_sjs1", version = "3.9."},
{groupId = "org.scala-lang", artifactId = "scala-library", version = "2.13."}
]
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
version = 3.9.10
maxColumn = 120
runner.dialect = scala213
runner.dialect = scala213source3
fileOverride {
"glob:**/scala-3/**" {
runner.dialect = scala3
Expand Down
11 changes: 8 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ val scala2_12 = "2.12.21"
val scala2_13 = "2.13.18"

val scala2 = List(scala2_12, scala2_13)
val scala3 = "3.3.8"
val scala3 = "3.9.0"

val scala2And3Versions = scala2 :+ scala3

Expand Down Expand Up @@ -57,6 +57,10 @@ ideSkipProject := (scalaVersion.value != ideScalaVersion) || thisProjectRef.valu
bspEnabled := !ideSkipProject.value
scalacOptions ~= (_.filterNot(Set("-Wconf:cat=other-match-analysis:error"))) // doesn't play well with macros

val scala2Source3 = scalacOptions ++= {
if (scalaVersion.value == scala3) Nil else Seq("-Xsource:3")
}

val testSettings = Seq(
publishArtifact := false,
scalacOptions ++= Seq("-Ywarn-dead-code"),
Expand Down Expand Up @@ -87,7 +91,7 @@ lazy val root = rootProject

lazy val util = projectMatrix
.in(file("util"))
.settings(libraryDependencies += tagging)
.settings(libraryDependencies += tagging, scala2Source3)
.jvmPlatform(scalaVersions = scala2And3Versions)
.jsPlatform(scalaVersions = scala2And3Versions)
.nativePlatform(scalaVersions = scala2And3Versions)
Expand All @@ -108,6 +112,7 @@ lazy val proxy = projectMatrix
.settings(
libraryDependencies ++= Seq(javassist, scalatest % Test),
compileOrder := CompileOrder.JavaThenScala,
scala2Source3,
javaOptions += "--add-opens java.base/java.lang=ALL-UNNAMED"
)
.dependsOn(macros % Test)
Expand Down Expand Up @@ -135,7 +140,7 @@ lazy val tests = projectMatrix

lazy val utilTests = projectMatrix
.in(file("util-tests"))
.settings(testSettings)
.settings(testSettings, scala2Source3)
.dependsOn(macros % "provided", util % Test, testUtil % Test)
.jvmPlatform(scalaVersions = scala2And3Versions)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ private[macwire] class CompanionCrimper[Q <: Quotes, T: Type](using val q: Q)(

def isCompanionApply(method: Symbol): Boolean =
method.isDefDef &&
!(method.flags is Flags.Private) &&
!(method.flags is Flags.Protected) &&
!method.flags.is(Flags.Private) &&
!method.flags.is(Flags.Protected) &&
returnType(method) <:< targetType &&
method.name == "apply"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ private[macwire] class ConstructorCrimper[Q <: Quotes, T: Type](using val q: Q)(
lazy val targetTypeD = targetType.dealias

private def isAccessibleConstructor(s: Symbol) =
s.isClassConstructor && !(s.flags is Flags.Private) && !(s.flags is Flags.Protected)
s.isClassConstructor && !s.flags.is(Flags.Private) && !s.flags.is(Flags.Protected)

private def isImplicit(f: Flags): Boolean = f.is(Flags.Implicit) || f.is(Flags.Given)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private[macwire] class EligibleValuesFinder[Q <: Quotes](log: Logger)(using val
}

private def isPublic(member: Symbol): Boolean = {
!((member.flags is Flags.Private) || (member.flags is Flags.Protected))
!(member.flags.is(Flags.Private) || member.flags.is(Flags.Protected))
}

case class EligibleValue(tpe: TypeRepr, expr: Tree) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class AutowireProviders[Q <: Quotes](using val q: Q)(
raw: Option[Expr[Any]] = None
)

private val classTypeRepr = TypeRepr.of[Class[_]]
private val classTypeRepr = TypeRepr.of[Class[?]]

private val providersFromRawDependencies =
@tailrec
Expand Down Expand Up @@ -88,7 +88,7 @@ class AutowireProviders[Q <: Quotes](using val q: Q)(
!member.fullName.contains("$default$") && // default params for copy on case classes
!member.fullName.matches(".*_\\d+") // tuple methods on case classes

def isPublic(member: Symbol): Boolean = !((member.flags is Flags.Private) || (member.flags is Flags.Protected))
def isPublic(member: Symbol): Boolean = !(member.flags.is(Flags.Private) || member.flags.is(Flags.Protected))

log.withBlock(s"detected a membersOf provider"):
val Apply(_, List(membersOf)) = t: @unchecked
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ object Constructor:
import q.reflect.*

def isAccessibleConstructor(s: Symbol) =
s.isClassConstructor && !(s.flags is Flags.Private) && !(s.flags is Flags.Protected)
s.isClassConstructor && !s.flags.is(Flags.Private) && !s.flags.is(Flags.Protected)

/** In some cases there is one extra (phantom) constructor. This happens when extended trait has implicit param:
*
Expand All @@ -73,7 +73,7 @@ object Constructor:
*/
def isPhantomConstructor(constructor: Symbol): Boolean = constructor.fullName.endsWith("$init$")

if forType.typeSymbol.flags is Flags.Trait then None
if forType.typeSymbol.flags.is(Flags.Trait) then None
else
val publicConstructors: Iterable[Symbol] =
val ctors = forType.typeSymbol.declarations
Expand Down Expand Up @@ -124,8 +124,8 @@ object Companion:

def isCompanionApply(method: Symbol): Boolean =
method.isDefDef &&
!(method.flags is Flags.Private) &&
!(method.flags is Flags.Protected) &&
!method.flags.is(Flags.Private) &&
!method.flags.is(Flags.Protected) &&
returnType(method) <:< forType &&
method.name == "apply"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ import scala.quoted.*

def showTypeName[T: Type](using q: Quotes): String = showTypeName(using q)(q.reflect.TypeRepr.of[T])
def showTypeName(using q: Quotes)(t: q.reflect.TypeRepr): String = t.typeSymbol.name
def showExprShort(using q: Quotes)(e: Expr[_]): String =
def showExprShort(using q: Quotes)(e: Expr[?]): String =
import q.reflect.*
e.asTerm.show(using Printer.TreeShortCode)
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ trait ProxyingInterceptor extends Interceptor {
def invoke(self: AnyRef, thisMethod: Method, _proceed: Method, args: Array[AnyRef]) = {
val invocationContext = new InvocationContext {
def parameters = args
def target = intercepted
def target: AnyRef = intercepted
def method = thisMethod

def proceedWithParameters(parameters: Array[AnyRef]) = thisMethod.invoke(intercepted, parameters: _*)
def proceedWithParameters(parameters: Array[AnyRef]) = thisMethod.invoke(intercepted, parameters*)
}

handle(invocationContext)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ object ProxyCreator {
case Some(unsafe) => unsafe.allocateInstance(proxiedClass)
case None =>
val constructor = findBestConstructor(proxiedClass)
constructor.newInstance(constructor.getParameterTypes.map(getDefaultValueForClass): _*)
constructor.newInstance(constructor.getParameterTypes.map(getDefaultValueForClass)*)
}

instance.asInstanceOf[ProxyObject].setHandler(methodHandler)
instance.asInstanceOf[T]
}

private def findBestConstructor(cls: Class[_]) = {
private def findBestConstructor(cls: Class[?]) = {
val ctors = cls.getConstructors
ctors.find(_.getParameterTypes.size == 0).getOrElse(ctors.head)
}

private val TypeDefaults = Map[Class[_], AnyRef](
private val TypeDefaults = Map[Class[?], AnyRef](
java.lang.Byte.TYPE -> java.lang.Byte.valueOf(0.toByte),
java.lang.Short.TYPE -> java.lang.Short.valueOf(0.toShort),
java.lang.Integer.TYPE -> java.lang.Integer.valueOf(0),
Expand All @@ -41,7 +41,7 @@ object ProxyCreator {
java.lang.Boolean.TYPE -> java.lang.Boolean.FALSE
)

private def getDefaultValueForClass(cls: Class[_]): AnyRef = TypeDefaults.getOrElse(cls, null)
private def getDefaultValueForClass(cls: Class[?]): AnyRef = TypeDefaults.getOrElse(cls, null)

private val UnsafeInstance: Option[Unsafe] = {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ import scala.reflect.ClassTag

object NoOpScope extends Scope {
def apply[T](createT: => T)(implicit tag: ClassTag[T]) = createT
def get[T](key: String, createT: => T) = throw new RuntimeException("Should never be called!")
def get[T](key: String, createT: => T): Nothing = throw new RuntimeException("Should never be called!")
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ trait ProxyingScope extends Scope {
val methodHandler = new MethodHandler() {
def invoke(self: Any, thisMethod: Method, proceed: Method, args: Array[AnyRef]) = {
val instance = get(key, createT)
thisMethod.invoke(instance, args: _*)
thisMethod.invoke(instance, args*)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ trait CompileTestsSupport extends BaseCompileTestsSupport {
val cm = universe.runtimeMirror(getClass.getClassLoader)

import scala.tools.reflect.ToolBox
val tb = cm.mkToolBox()
val tb = cm.mkToolBox(options = "-Xsource:3")

val source = loadTest("/test-cases/" + testName, imports)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import scala.io.Source
import java.nio.file.Path
import java.nio.file.Paths
import java.nio.file.Files
import java.nio.file.OpenOption
import java.nio.file.StandardOpenOption

import dotty.tools.dotc.reporting.{ThrowingReporter, Diagnostic}
import dotty.tools.dotc.interfaces.Diagnostic.WARNING
import dotty.tools.dotc.Driver
import java.io.IOException

Expand Down Expand Up @@ -52,13 +52,13 @@ trait CompileTestsSupport extends BaseCompileTestsSupport with OptionValues {
val testReporter = new TestReporter
val reporter = testReporter
val classpath = Array("-classpath", Properties.currentClasspath)

driver.process(classpath :+ path.toString, reporter)

val infos = testReporter.storedInfos
// since Scala 3.9 update, the "N errors" found summary is reported as a position-less warning
val infosWithoutSummary = testReporter.storedInfos.filterNot(msg => msg.level == WARNING && !msg.pos.exists)

def verifyInfo(level: Int, expected: List[String]) = {
val actual = infos.filter(_.level == level).map(_.message)
val actual = infosWithoutSummary.filter(_.level == level).map(_.message)

if (expected.size > 0) {
val info = actual.mkString("\n")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ object Module {
def b(b: B) = {
wire[C]
}
b _
(bArg: B) => b(bArg)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ object Module {
if (useWire) wire[C]
else new C(new A, new B)
}
b _
(bArg: B) => (useWire: Boolean) => b(bArg)(useWire)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ object Module {
// method's parameter 'a' will shadow def 'a'.
def a(a: A) = {
def b(b: B): C = wire[C]
b _
(bArg: B) => b(bArg)
}
}

Expand Down
4 changes: 2 additions & 2 deletions tests/src/test/resources/test-cases/selfType.success
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ trait ModuleSimple { this : AProvider =>
lazy val c = wire[C]
}

trait ModuleMultiple { this : AProvider with BProvider =>
trait ModuleMultiple { this : AProvider & BProvider =>
lazy val c = wire[C]
}

Expand All @@ -38,7 +38,7 @@ require(TestMultiple.c.a == TestMultiple.a)
require(TestMultiple.c.b == TestMultiple.b)

object ProviderAliasing {
type AAndB = AProvider with BProvider
type AAndB = AProvider & BProvider
}

trait AliasedMultiModule { this: ProviderAliasing.AAndB =>
Expand Down
2 changes: 1 addition & 1 deletion tests/src/test/resources/test-cases/wireWith.success
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ object Test {
lazy val a: A = wire[A]
lazy val b: B = wire[B]

lazy val c: C = wireWith(C.factory _)
lazy val c: C = wireWith((a: A, b: B) => C.factory(a, b))
}

require(Test.c.a eq Test.a)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ object A {
lazy val n = 0
implicit lazy val s: String = "s"

wireWith(A.make _)
wireWith((n: Int) => A.make(n))
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ object Test extends BProvider {
}

lazy val a: A = wire[A]
lazy val c: C = wireWith(C.factory _)
lazy val c: C = wireWith((a: A) => (b: B) => C.factory(a)(b))
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
object Module {
def create(blueberryArg: Berry @@ Blue) = {
def inner(blackberryArg: Berry @@ Black): BlueberryBasket = wire[BlueberryBasket]
inner _
(arg: Berry @@ Black) => inner(arg)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
object Module {
def create(blueberryArg1: Berry @@ Blue) = {
def inner(blueberryArg2: Berry @@ Blue): BlueberryBasket = wire[BlueberryBasket]
inner _
(arg: Berry @@ Blue) => inner(arg)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
object Module {
def create(blackberryArg: Berry @@ Black) = {
def inner(raspberryArg: Berry @@ Red): BlueberryBasket = wire[BlueberryBasket]
inner _
(arg: Berry @@ Red) => inner(arg)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class WiredTest extends AnyFlatSpec with Matchers {
import WiredTest._

def createInstanceFactoryMap(instances: AnyRef*): InstanceFactoryMap = Map(
instances.map(i => i.getClass -> (() => i)): _*
instances.map(i => i.getClass -> (() => i))*
)

val implsMap1 = createInstanceFactoryMap(new X, new Y, new Z)
Expand Down Expand Up @@ -47,7 +47,7 @@ class WiredTest extends AnyFlatSpec with Matchers {
testLookup(implsMap4, classOf[Y], 0)
}

def testLookup(map: InstanceFactoryMap, cls: Class[_], expectedCount: Int): Unit = {
def testLookup(map: InstanceFactoryMap, cls: Class[?], expectedCount: Int): Unit = {
val result = new Wired(map).lookup(cls)
result should have size (expectedCount)
result.foreach(r => cls.isAssignableFrom(r.getClass) should be(true))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ private[macwire] trait DynamicInstantiate {
}
}

ctor.newInstance(params: _*).asInstanceOf[T]
ctor.newInstance(params*).asInstanceOf[T]
}

protected def lookup[T](cls: Class[T]): List[T]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ private[macwire] trait InstanceLookup {
case l => throw new RuntimeException(s"Found multiple implementations of class $cls: $l!")
}

private def prepareLookupMap: Map[Class[_], List[() => AnyRef]] = {
private def prepareLookupMap: Map[Class[?], List[() => AnyRef]] = {
instanceFactoryMap.toList
.flatMap { case (startingCls, impl) =>
def allSuperClasses(cls: Class[_]): List[Class[_]] = {
def allSuperClasses(cls: Class[?]): List[Class[?]] = {
if (cls == null) {
Nil
} else {
Expand Down
2 changes: 1 addition & 1 deletion util/src/main/scala/com/softwaremill/macwire/Wired.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ class Wired(protected val instanceFactoryMap: InstanceFactoryMap) extends Instan
}

object Wired {
private[macwire] type InstanceFactoryMap = Map[Class[_], () => AnyRef]
private[macwire] type InstanceFactoryMap = Map[Class[?], () => AnyRef]
def apply(implsByClass: InstanceFactoryMap) = new Wired(implsByClass)
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ package object tagging {

implicit class AndTagger[T, U](t: T @@ U) {
@deprecated("Use com.softwaremill.tagging instead")
def andTaggedWith[V]: T @@ (U with V) = new com.softwaremill.tagging.AndTagger[T, U](t).andTaggedWith[V]
def andTaggedWith[V]: T @@ (U & V) = new com.softwaremill.tagging.AndTagger[T, U](t).andTaggedWith[V]
}
}
Loading