Skip to content

Commit

Permalink
Fix Scala 2.12 compile
Browse files Browse the repository at this point in the history
  • Loading branch information
Katrix committed Apr 26, 2020
1 parent 2188b92 commit 0f1bd1e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
18 changes: 9 additions & 9 deletions data/src/main/scala-2.12/ackcord/SnowflakeMap.scala
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,16 @@ class SnowflakeMap[K, +V](private val inner: LongMap[V])

final override def size: Int = inner.size

final override def get(key: Key): Option[V] = inner.get(key)
final override def get(key: Key): Option[V] = inner.get(key.toUnsignedLong)

final override def getOrElse[V1 >: V](key: Key, default: => V1): V1 = inner.getOrElse(key, default)
final override def getOrElse[V1 >: V](key: Key, default: => V1): V1 = inner.getOrElse(key.toUnsignedLong, default)

final override def apply(key: Key): V = inner.apply(key)
final override def apply(key: Key): V = inner.apply(key.toUnsignedLong)

override def +[V1 >: V](kv: (Key, V1)): SnowflakeMap[K, V1] = new SnowflakeMap(inner.updated(kv._1, kv._2))
override def +[V1 >: V](kv: (Key, V1)): SnowflakeMap[K, V1] = new SnowflakeMap(inner.updated(kv._1.toUnsignedLong, kv._2))

override def updated[V1 >: V](key: Key, value: V1): SnowflakeMap[K, V1] =
new SnowflakeMap(inner.updated(key, value))
new SnowflakeMap(inner.updated(key.toUnsignedLong, value))

/**
* Updates the map, using the provided function to resolve conflicts if the key is already present.
Expand All @@ -118,9 +118,9 @@ class SnowflakeMap[K, +V](private val inner: LongMap[V])
* @return The updated map.
*/
def updateWith[S >: V](key: Key, value: S, f: (V, S) => S): SnowflakeMap[K, S] =
new SnowflakeMap(inner.updateWith(key, value, f))
new SnowflakeMap(inner.updateWith(key.toUnsignedLong, value, f))

override def -(key: Key): SnowflakeMap[K, V] = new SnowflakeMap(inner - key)
override def -(key: Key): SnowflakeMap[K, V] = new SnowflakeMap(inner - key.toUnsignedLong)

/**
* A combined transform and filter function. Returns an `SnowflakeMap` such that
Expand Down Expand Up @@ -188,13 +188,13 @@ object SnowflakeMap {
* Create a snowflake map with a single value.
*/
def singleton[K, V](key: SnowflakeType[K], value: V): SnowflakeMap[K, V] =
new SnowflakeMap(LongMap.singleton(key, value))
new SnowflakeMap(LongMap.singleton(key.toUnsignedLong, value))

/**
* Create a snowflake map from multiple values.
*/
def apply[K, V](elems: (SnowflakeType[K], V)*): SnowflakeMap[K, V] =
new SnowflakeMap(LongMap.apply(elems: _*))
new SnowflakeMap(LongMap.apply(elems.map(t => t._1.toUnsignedLong -> t._2): _*))

//alias for apply to make it easier to cross compile
def from[K, V](iterable: Iterable[(SnowflakeType[K], V)]): SnowflakeMap[K, V] = apply(iterable.toSeq: _*)
Expand Down
17 changes: 11 additions & 6 deletions data/src/main/scala/ackcord/data/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ package object data {

type SnowflakeType[+A] = SnowflakeType.SnowflakeType[A]
object SnowflakeType {
type SnowflakeType[+A]
sealed trait Tag
type SnowflakeType[+A] <: Tag
def apply[A](long: Long): SnowflakeType[A] = long.asInstanceOf[SnowflakeType[A]]
def apply[A](content: String): SnowflakeType[A] = apply[A](JLong.parseUnsignedLong(content))
def apply[A](other: SnowflakeType[_]): SnowflakeType[A] = other.asInstanceOf[SnowflakeType[A]]
Expand All @@ -49,7 +50,7 @@ package object data {

private val DiscordEpoch = 1420070400000L

implicit class SnowflakeTypeSyntax[A](private val snowflake: SnowflakeType[A]) extends AnyVal {
implicit class SnowflakeTypeSyntax(private val snowflake: SnowflakeType[_]) extends AnyVal {
def creationDate: Instant = Instant.ofEpochMilli(DiscordEpoch + (toUnsignedLong >> 22))
def asString: String = JLong.toUnsignedString(toUnsignedLong)

Expand Down Expand Up @@ -248,7 +249,8 @@ package object data {
*/
type Permission = Permission.Permission
object Permission {
type Permission
sealed trait Tag
type Permission <: Tag

private[data] def apply(long: Long): Permission = long.asInstanceOf[Permission]

Expand Down Expand Up @@ -374,7 +376,8 @@ package object data {

type UserFlags = UserFlags.UserFlags
object UserFlags {
type UserFlags
sealed trait Tag
type UserFlags <: Tag

private[data] def apply(int: Int): UserFlags = int.asInstanceOf[UserFlags]

Expand Down Expand Up @@ -431,7 +434,8 @@ package object data {

type MessageFlags = MessageFlags.MessageFlags
object MessageFlags {
type MessageFlags
sealed trait Tag
type MessageFlags <: Tag

private[data] def apply(int: Int): MessageFlags = int.asInstanceOf[MessageFlags]

Expand Down Expand Up @@ -482,7 +486,8 @@ package object data {

type SystemChannelFlags = SystemChannelFlags.SystemChannelFlags
object SystemChannelFlags {
type SystemChannelFlags
sealed trait Tag
type SystemChannelFlags <: Tag

private[data] def apply(int: Int): SystemChannelFlags = int.asInstanceOf[SystemChannelFlags]

Expand Down
4 changes: 2 additions & 2 deletions exampleCore/src/main/scala/ackcord/examplecore/Example.scala
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,11 @@ class ExampleMain(ctx: ActorContext[ExampleMain.Command], log: Logger, settings:
commands.CommandDescription("MaybeFail", "A command that sometimes fails and throws an exception")
),
NewCommandsEntry(
controller.ratelimitTest("ratelimitTest", requests.sinkIgnore),
controller.ratelimitTest("ratelimitTest", requests.sinkIgnore[Any]),
commands.CommandDescription("Ratelimit test", "Checks that ratelimiting is working as intended")
),
NewCommandsEntry(
controller.ratelimitTest("ratelimitTestOrdered", requests.sinkIgnore(Requests.RequestProperties.ordered)),
controller.ratelimitTest("ratelimitTestOrdered", requests.sinkIgnore[Any](Requests.RequestProperties.ordered)),
commands.CommandDescription("Ratelimit test", "Checks that ratelimiting is working as intended")
),
NewCommandsEntry(
Expand Down

0 comments on commit 0f1bd1e

Please sign in to comment.