Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dotty syntax compat #28837

Closed
wants to merge 49 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
6718c97
update sbt-scalafix 0.9.13
giabao Apr 1, 2020
985d336
simplify Dependencies / sslConfigCore sbt setting
giabao Apr 6, 2020
e3a9eff
update ssl-config-core 0.4.2
giabao Apr 6, 2020
00940ef
update scalacheck-1-14 3.1.1.1
giabao Apr 6, 2020
ac2397e
sbt: fix an implicitConversions warning
giabao Apr 6, 2020
f9acfad
sbt: Add dotty build settings
giabao Apr 6, 2020
b16d3a4
sbt misc: Add comment about how to import project into IntelliJ with …
giabao Apr 7, 2020
86d7499
scalafix ConstructorProcedureSyntax
giabao Apr 2, 2020
001d774
scalafix FinalObject
giabao Apr 2, 2020
13b8acb
FinalObject fix - for scalafix ignored files
giabao Apr 6, 2020
a0f063a
scalafix: Using ExplicitResultTypes rule to add explicit type for imp…
giabao Apr 5, 2020
4c388be
rollback settings used to run scalafix ExplicitResultTypes
giabao Apr 5, 2020
7bfd2fe
explicitly declaring type for implicit local val / def
giabao Apr 6, 2020
ec61635
dotty compatible syntax
giabao Mar 27, 2020
6511e53
Only replace all `Props[T]()` to `Props[T]` with all type T. Similar …
giabao Mar 27, 2020
269caba
Remove SerialVersionUID on traits
giabao Mar 27, 2020
96b825a
dotty implicit resolution compat: Add `import akka.actor.actorRef2Sca…
giabao Mar 27, 2020
36a6e1a
dotty compat: don't use Early Initializers in LightArrayRevolverSched…
giabao Mar 27, 2020
c77d9b3
make some case class constructors package private instead of `private…
giabao Mar 27, 2020
a108800
Fix Name clash dotty compile error in akka-actor's akka.util.Index
giabao Mar 27, 2020
2249fdd
Fix dotty Type Mismatch Error in class ActorRef
giabao Mar 27, 2020
e227549
explicitly import java.lang.Enum to shadow Enum in dotty
giabao Mar 27, 2020
e65846f
explicitly declare a method type to fix dotty compile errors
giabao Mar 27, 2020
c070cd7
move TypedMultiMapSpec to scala-2 source dir
giabao Mar 27, 2020
e50d8ee
TestKit: Use trait parameters instead of Early Initializers for dotty
giabao Mar 27, 2020
c72d1b7
fix DockerBindDnsService tests in dotty. Related scala/bug#11924
giabao Mar 27, 2020
936fc79
fix dotty compile error: non-private constructor Cache in class Cache…
giabao Mar 27, 2020
c5668f1
fix dotty compile error when write `def copy` for generic case class.…
giabao Mar 27, 2020
cf72f44
fix compile errors because dotty can't infer types for some vals/ defs
giabao Apr 5, 2020
75cedfe
fix dotty compile error: No ClassTag available for Nothing, Null
giabao Apr 5, 2020
018a79d
TestActorRef: don't use Early Initializers (dropped in dotty)
giabao Mar 27, 2020
31376b2
fix dotty compile error: non-private method unstashed in class StashB…
giabao Mar 27, 2020
1febdae
fix dotty compile error: missing requirement for self type
giabao Mar 27, 2020
0bea666
dotty compat in testkit & actor-tests: use path-dependent types inste…
giabao Mar 27, 2020
923ad89
fix type shadow compile error in scala 2.12
giabao Mar 27, 2020
d41317b
fix dotty compile errors `Cannot find LogSource`
giabao Mar 27, 2020
763c84a
re-impl LocalReceptionist using path-dependent type instead of genera…
giabao Mar 27, 2020
69c7d1e
fix dotty compile error: Missing type parameter for OutputStreamAppender
giabao Mar 31, 2020
6597c81
prevent dotty to remove unused private fields
giabao Mar 27, 2020
7f734b6
AkkaDisciplinePlugin don't need to depend on Scalafix
giabao Mar 29, 2020
b35153d
fix dotty compile errors: parentheses are required around the paramet…
giabao Mar 31, 2020
39aa1cc
fix dotty compile errors: Reference to SayHello is ambiguous
giabao Mar 31, 2020
da85d89
Fix NullPointerException in DockerBindDnsService.atStartup
giabao Mar 28, 2020
242c4c9
fix dotty compile error: non-private method apply in object SessionBe…
giabao Apr 4, 2020
174dfdf
fix a dotty compile error when using `implicit class` conversion on `…
giabao Apr 4, 2020
aecd9f1
fix dotty compile error in construct: `val x = new { def f = ??? }; x.f`
giabao Apr 4, 2020
57ed266
scalafmtAll
giabao Apr 7, 2020
fbc29f6
mima ProblemFilters
giabao Apr 7, 2020
ebb8527
fix dotty compile errors `ambiguous reference`
giabao Apr 7, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
7 changes: 7 additions & 0 deletions .scalafix.conf
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
// .scalafix.conf
rules = [
RemoveUnused
// ExplicitResultTypes
// "github:ohze/scalafix-rules/ConstructorProcedureSyntax"
// "github:ohze/scalafix-rules/FinalObject"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so this was been used locally?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. It was been used locally but we could just uncomment the lines to run on CI

]
ExplicitResultTypes {
memberVisibility = [] # only rewrite implicit members
skipSimpleDefinitions = []
}
RemoveUnused.imports = true
RemoveUnused.privates = false
RemoveUnused.locals = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,37 +28,32 @@ final case class CapturedLogEvent(level: Level, message: String, cause: Option[T
message: String,
errorCause: Optional[Throwable],
marker: Optional[Marker],
mdc: java.util.Map[String, Any]) {
mdc: java.util.Map[String, Any]) =
this(level, message, errorCause.asScala, marker.asScala)
}

/**
* Constructor for Java API
*/
def this(level: Level, message: String) {
def this(level: Level, message: String) =
this(level, message, Option.empty, Option.empty)
}

/**
* Constructor for Java API
*/
def this(level: Level, message: String, errorCause: Throwable) {
def this(level: Level, message: String, errorCause: Throwable) =
this(level, message, Some(errorCause), Option.empty[Marker])
}

/**
* Constructor for Java API
*/
def this(level: Level, message: String, marker: Marker) {
def this(level: Level, message: String, marker: Marker) =
this(level, message, Option.empty[Throwable], Some(marker))
}

/**
* Constructor for Java API
*/
def this(level: Level, message: String, errorCause: Throwable, marker: Marker) {
def this(level: Level, message: String, errorCause: Throwable, marker: Marker) =
this(level, message, Some(errorCause), Some(marker))
}

def getErrorCause: Optional[Throwable] = cause.asJava

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ object Effect {
def duration(): java.time.Duration = d.asJava
}

final case object ReceiveTimeoutCancelled extends ReceiveTimeoutCancelled
case object ReceiveTimeoutCancelled extends ReceiveTimeoutCancelled

sealed abstract class ReceiveTimeoutCancelled extends Effect

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ object TestKitSettings {

private object Ext extends ExtensionId[Ext] {
override def createExtension(system: ActorSystem[_]): Ext = new Ext(system)
def get(system: ActorSystem[_]): Ext = apply(system)
def get(system: ActorSystem[_]): Ext = this.apply(system)
}

private class Ext(system: ActorSystem[_]) extends Extension {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ private[akka] final class BehaviorTestKitImpl[T](_path: ActorPath, _initialBehav
with akka.actor.testkit.typed.scaladsl.BehaviorTestKit[T] {

// really this should be private, make so when we port out tests that need it
private[akka] val context = new EffectfulActorContext[T](_path, () => currentBehavior)
// need explicitly declaring type here because lampepfl/dotty#8675
private[akka] val context: EffectfulActorContext[T] = new EffectfulActorContext[T](_path, () => currentBehavior)

private[akka] def as[U]: BehaviorTestKitImpl[U] = this.asInstanceOf[BehaviorTestKitImpl[U]]

Expand Down Expand Up @@ -128,7 +129,7 @@ private[akka] final class BehaviorTestKitImpl[T](_path: ActorPath, _initialBehav
} catch handleException
}

override def runOne(): Unit = run(selfInbox.receiveMessage())
override def runOne(): Unit = run(selfInbox().receiveMessage())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better to remove () from def selfInbox(): TestInbox[T]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also think that but the change will cause source backward incompatible.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe break compatibility is acceptable with testkit modules?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a similar problem with Props.apply & TypedProps.apply.
So I still don't include this commit into this PR although that commit is need for dotty :(
Or the break change here is also acceptable?
(note that it only break source backward compatible, still binary compatible)


override def signal(signal: Signal): Unit = {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ private[akka] final class FunctionRef[-T](override val path: ActorPath, send: (T
new FunctionRef[U](p, (message, _) => {
val m = f(message);
if (m != null) {
selfInbox.ref ! m; i.selfInbox.ref ! message
selfInbox.ref ! m; i.selfInbox().ref ! message
}
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ private[akka] object ActorTestKitGuardian {
final case class StopActor[T](ref: ActorRef[T], replyTo: ActorRef[Ack.type]) extends TestKitCommand
final case class ActorStopped[T](replyTo: ActorRef[Ack.type]) extends TestKitCommand

final case object Ack
case object Ack

val testKitGuardian: Behavior[TestKitCommand] = Behaviors.receive[TestKitCommand] {
case (context, SpawnActor(name, behavior, reply, props)) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ abstract class BehaviorTestKit[T] {
/**
* The self reference of the actor living inside this testkit.
*/
def getRef(): ActorRef[T] = selfInbox.getRef()
def getRef(): ActorRef[T] = selfInbox().getRef()

/**
* Requests all the effects. The effects are consumed, subsequent calls will only
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ final class ActorTestKit private[akka] (
*/
def stop[T](ref: ActorRef[T], max: FiniteDuration = timeout.duration): Unit =
try {
Await.result(internalTestKitGuardian.ask { x: ActorRef[ActorTestKitGuardian.Ack.type] =>
Await.result(internalTestKitGuardian.ask { (x: ActorRef[ActorTestKitGuardian.Ack.type]) =>
ActorTestKitGuardian.StopActor(ref, x)
}, max)
} catch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ trait BehaviorTestKit[T] {
/**
* The self reference of the actor living inside this testkit.
*/
def ref: ActorRef[T] = selfInbox.ref
def ref: ActorRef[T] = selfInbox().ref

/**
* Requests all the effects. The effects are consumed, subsequent calls will only
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ object BehaviorTestKitSpec {
context.stop(child)
Behaviors.same
case SpawnAdapter =>
context.spawnMessageAdapter { r: Reproduce =>
context.spawnMessageAdapter { (r: Reproduce) =>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd probably use context.spawnMessageAdapter[Reproduce] { r =>, but that's for another PR

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

without parentheses will cause error:

error] -- Error: /Users/thanhbv/ohze/oss/akka/akka-actor-testkit-typed/src/test/scala/akka/actor/testkit/typed/scaladsl/BehaviorTestKitSpec.scala:72:51 
[error] 72 |          context.spawnMessageAdapter[Reproduce] { r: Reproduce =>
[error]    |                                                   ^^^^^^^^^^^^
[error]    |parentheses are required around the parameter of a lambda
[error]    |This construct can be rewritten automatically under -language:Scala2Compat -rewrite.

SpawnAnonymous(r.times)
}
Behaviors.same
case SpawnAdapterWithName(name) =>
context.spawnMessageAdapter({ r: Reproduce =>
context.spawnMessageAdapter({ (r: Reproduce) =>
SpawnAnonymous(r.times)
}, name)
Behaviors.same
Expand Down Expand Up @@ -310,7 +310,7 @@ class BehaviorTestKitSpec extends AnyWordSpec with Matchers with LogCapturing {
val d = TestInbox[Done]()
testkit.run(KillSession(sessionRef, d.ref))

d.receiveAll shouldBe Seq(Done)
d.receiveAll() shouldBe Seq(Done)
testkit.expectEffectType[Stopped]
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class TestProbeSpec extends ScalaTestWithActorTestKit with AnyWordSpecLike with
val probe = createTestProbe[EventT]()
eventsT(10).forall { e =>
probe.ref ! e
probe.receiveMessage == e
probe.receiveMessage() == e
} should ===(true)

probe.expectNoMessage()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class ActorConfigurationVerificationSpec
with BeforeAndAfterEach {
import ActorConfigurationVerificationSpec._

override def atStartup: Unit = {
override def atStartup(): Unit = {
system.eventStream.publish(Mute(EventFilter[ConfigurationException]("")))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class ActorLifeCycleSpec extends AkkaSpec with BeforeAndAfterEach with ImplicitS
"log failures in postStop" in {
val a = system.actorOf(Props(new Actor {
def receive = Actor.emptyBehavior
override def postStop: Unit = { throw new Exception("hurrah") }
override def postStop(): Unit = { throw new Exception("hurrah") }
}))
EventFilter[Exception]("hurrah", occurrences = 1).intercept {
a ! PoisonPill
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ class ActorRefSpec extends AkkaSpec("""

Await.ready(latch, timeout.duration)

latch.reset
latch.reset()

clientRef ! "complex2"
clientRef ! "simple"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ class ActorSelectionSpec extends AkkaSpec with DefaultTimeout {

"identify actors with wildcard selection correctly" in {
val creator = TestProbe()
implicit def self = creator.ref
implicit def self: ActorRef = creator.ref
val top = system.actorOf(p, "a")
val b1 = Await.result((top ? Create("b1")).mapTo[ActorRef], timeout.duration)
val b2 = Await.result((top ? Create("b2")).mapTo[ActorRef], timeout.duration)
Expand Down
10 changes: 5 additions & 5 deletions akka-actor-tests/src/test/scala/akka/actor/ActorSystemSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ object ActorSystemSpec {
extends MessageDispatcherConfigurator(_config, _prerequisites) {
private val instance = new Dispatcher(
this,
config.getString("id"),
config.getInt("throughput"),
config.getNanosDuration("throughput-deadline-time"),
this.config.getString("id"),
this.config.getInt("throughput"),
this.config.getNanosDuration("throughput-deadline-time"),
configureExecutor(),
config.getMillisDuration("shutdown-timeout")) {
this.config.getMillisDuration("shutdown-timeout")) {
val doneIt = new Switch
override protected[akka] def registerForExecution(
mbox: Mailbox,
Expand Down Expand Up @@ -263,7 +263,7 @@ class ActorSystemSpec extends AkkaSpec(ActorSystemSpec.config) with ImplicitSend

"reliably create waves of actors" in {
import system.dispatcher
implicit val timeout = Timeout((20 seconds).dilated)
implicit val timeout: Timeout = Timeout((20 seconds).dilated)
val waves = for (_ <- 1 to 3) yield system.actorOf(Props[ActorSystemSpec.Waves]) ? 50000
Await.result(Future.sequence(waves), timeout.duration + 5.seconds) should ===(Vector("done", "done", "done"))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class ActorWithBoundedStashSpec
with ImplicitSender {
import ActorWithBoundedStashSpec._

override def atStartup: Unit = {
override def atStartup(): Unit = {
system.eventStream.publish(Mute(EventFilter.warning(pattern = ".*received dead letter from.*hello.*")))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ object ActorWithStashSpec {
def greeted: Receive = {
case "bye" =>
state.s = "bye"
state.finished.await
state.finished.await()
case _ => // do nothing
}

Expand Down Expand Up @@ -63,7 +63,7 @@ object ActorWithStashSpec {
context.unbecome()
case _ => stash()
}
case "done" => state.finished.await
case "done" => state.finished.await()
case _ => stash()
}
}
Expand Down Expand Up @@ -105,19 +105,19 @@ class JavaActorWithStashSpec extends StashJavaAPI with JUnitSuiteLike
class ActorWithStashSpec extends AkkaSpec with DefaultTimeout with BeforeAndAfterEach {
import ActorWithStashSpec._

override def atStartup: Unit = {
override def atStartup(): Unit = {
system.eventStream.publish(Mute(EventFilter[Exception]("Crashing...")))
}

override def beforeEach() = state.finished.reset
override def beforeEach() = state.finished.reset()

"An Actor with Stash" must {

"stash messages" in {
val stasher = system.actorOf(Props(new StashingActor))
stasher ! "bye"
stasher ! "hello"
state.finished.await
state.finished.await()
state.s should ===("bye")
}

Expand All @@ -130,7 +130,7 @@ class ActorWithStashSpec extends AkkaSpec with DefaultTimeout with BeforeAndAfte
protoActor ! "write"
protoActor ! "close"
protoActor ! "done"
state.finished.await
state.finished.await()
}

"throw an IllegalStateException if the same messages is stashed twice" in {
Expand Down
10 changes: 5 additions & 5 deletions akka-actor-tests/src/test/scala/akka/actor/DeathWatchSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ object DeathWatchSpec {
context.become {
case Terminated(`currentKid`) =>
testActor ! "GREEN"
context unbecome
context.unbecome()
}
}
}
Expand Down Expand Up @@ -83,7 +83,7 @@ trait DeathWatchSpec { this: AkkaSpec with ImplicitSender with DefaultTimeout =>

"The Death Watch" must {
def expectTerminationOf(actorRef: ActorRef) =
expectMsgPF(5 seconds, actorRef + ": Stopped or Already terminated when linking") {
expectMsgPF(5 seconds, actorRef.toString + ": Stopped or Already terminated when linking") {
case WrappedTerminated(Terminated(`actorRef`)) => true
}

Expand Down Expand Up @@ -210,19 +210,19 @@ trait DeathWatchSpec { this: AkkaSpec with ImplicitSender with DefaultTimeout =>
}

"only notify when watching" in {
val subject = system.actorOf(Props[EmptyActor]())
val subject = system.actorOf(Props[EmptyActor])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is related to ohze@34d57cd (not included here).

And commented here: #28837 (comment)

where you say:

although that commit is need for dotty

Do you really need to remove ()? I did a quick tests on a tiny dotty project and is does compile fine.

case class Props(cls: Class[_])
object Props {
  def apply[T: ClassTag](): Props = Props(implicitly[ClassTag[T]].runtimeClass)
}


val p = Props[String]()
println(p.cls)
[info] running Main 
class java.lang.String

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I think I got why this is needed.

It's not needed by dotty, but it will be better to remove because then users can't call it as previously Props[EmptyActor].

The problem is that if we remove we make it source incompatible. We can be sure that there are many projects out there using Props[EmptyActor]().

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we are tackling this from the wrong side. The goal of the PR here, if I understand it correctly, is to make the code source compatible with the Dotty compiler. That said, we should not remove () at all. And we should it in the Akka code base in all places that Dotty requires it.

The day that we provide the binaries for Dotty/Scala3, a user willing to move to Dotty/Scala3 will have to add () in all places they omit it before.


testActor
.asInstanceOf[InternalActorRef]
.sendSystemMessage(DeathWatchNotification(subject, existenceConfirmed = true, addressTerminated = false))

// the testActor is not watching subject and will not receive a Terminated msg
expectNoMessage
expectNoMessage()
}

"discard Terminated when unwatched between sysmsg and processing" in {
val t1, t2 = TestLatch()
val w = system.actorOf(Props[WUWatcher]().withDeploy(Deploy.local), "myDearWatcher")
val w = system.actorOf(Props[WUWatcher].withDeploy(Deploy.local), "myDearWatcher")
val p = TestProbe()
w ! W(p.ref)
w ! Latches(t1, t2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ import org.scalatestplus.junit.JUnitSuiteLike
class JavaExtensionSpec extends JavaExtension with JUnitSuiteLike

object TestExtension extends ExtensionId[TestExtension] with ExtensionIdProvider {
def lookup = this
def lookup() = this
def createExtension(s: ExtendedActorSystem) = new TestExtension(s)
}

// Dont't place inside ActorSystemSpec object, since it will not be garbage collected and reference to system remains
class TestExtension(val system: ExtendedActorSystem) extends Extension

object FailingTestExtension extends ExtensionId[FailingTestExtension] with ExtensionIdProvider {
def lookup = this
def lookup() = this
def createExtension(s: ExtendedActorSystem) = new FailingTestExtension(s)

class TestException extends IllegalArgumentException("ERR") with NoStackTrace
Expand Down
Loading