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
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.pekko.event

import org.apache.pekko
import pekko.testkit.PekkoSpec

object LogSourceSpec {
class LogsWithGetClass(system: pekko.actor.ActorSystem) {
// `getClass` returns `Class[? <: LogsWithGetClass]`, which did not compile on Scala 3
val log: LoggingAdapter = Logging(system, getClass)
val logSource: (String, Class[?]) = LogSource(getClass, system)
}
}

class LogSourceSpec extends PekkoSpec {
import LogSourceSpec._

"LogSource" must {

"resolve an implicit LogSource for the result of getClass" in {
val subject = new LogsWithGetClass(system)
subject.logSource._1 should ===(s"LogSourceSpec$$LogsWithGetClass($system)")
subject.logSource._2 should ===(classOf[LogsWithGetClass])
subject.log.isInstanceOf[BusLogging] should ===(true)
}

"resolve an implicit LogSource for a class literal" in {
val logSource: (String, Class[?]) = LogSource(classOf[LogsWithGetClass])
logSource._1 should ===("LogSourceSpec$LogsWithGetClass")
logSource._2 should ===(classOf[LogsWithGetClass])
}

"resolve an implicit LogSource for a wildcard class" in {
val c: Class[?] = classOf[LogsWithGetClass]
val logSource: (String, Class[?]) = LogSource(c)
logSource._1 should ===("LogSourceSpec$LogsWithGetClass")
logSource._2 should ===(classOf[LogsWithGetClass])
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.pekko.event

import org.apache.pekko.annotation.InternalApi

/**
* INTERNAL API
*
* Scala 2 resolves [[LogSource.fromAnyClass]] for `getClass` results, so no extra implicits are needed.
*/
@InternalApi
private[event] trait LogSourceCompat
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.pekko.event

import org.apache.pekko.annotation.InternalApi

/**
* INTERNAL API
*
* Lower priority implicits for [[LogSource]]. Scala 3 does not match `getClass`, which returns
* `Class[? <: T]`, against [[LogSource.fromAnyClass]]. This is not in the shared sources because
* Scala 2 reports it as ambiguous with `fromAnyClass`.
*/
@InternalApi
private[event] trait LogSourceCompat {
implicit def fromAnySubClass[T]: LogSource[Class[? <: T]] =
LogSource.fromClass.asInstanceOf[LogSource[Class[? <: T]]]
}
2 changes: 1 addition & 1 deletion actor/src/main/scala/org/apache/pekko/event/Logging.scala
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ class DummyClassForStringSources
* <li>anything else gives compile error unless implicit [[pekko.event.LogSource]] is in scope for it</li>
* </ul>
*/
object LogSource {
object LogSource extends LogSourceCompat {
implicit val fromString: LogSource[String] = new LogSource[String] {
def genString(s: String) = s
override def genString(s: String, system: ActorSystem) = s + "(" + system + ")"
Expand Down
Loading