From 0f1bd1e8d951e781ed578ef1f0a4118fd1703f56 Mon Sep 17 00:00:00 2001 From: Katrix Date: Sun, 26 Apr 2020 18:30:54 +0200 Subject: [PATCH] Fix Scala 2.12 compile --- .../main/scala-2.12/ackcord/SnowflakeMap.scala | 18 +++++++++--------- data/src/main/scala/ackcord/data/package.scala | 17 +++++++++++------ .../scala/ackcord/examplecore/Example.scala | 4 ++-- 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/data/src/main/scala-2.12/ackcord/SnowflakeMap.scala b/data/src/main/scala-2.12/ackcord/SnowflakeMap.scala index f5a77c78..740a0e4d 100644 --- a/data/src/main/scala-2.12/ackcord/SnowflakeMap.scala +++ b/data/src/main/scala-2.12/ackcord/SnowflakeMap.scala @@ -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. @@ -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 @@ -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: _*) diff --git a/data/src/main/scala/ackcord/data/package.scala b/data/src/main/scala/ackcord/data/package.scala index 1d00f145..298880f1 100644 --- a/data/src/main/scala/ackcord/data/package.scala +++ b/data/src/main/scala/ackcord/data/package.scala @@ -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]] @@ -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) @@ -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] @@ -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] @@ -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] @@ -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] diff --git a/exampleCore/src/main/scala/ackcord/examplecore/Example.scala b/exampleCore/src/main/scala/ackcord/examplecore/Example.scala index 0fcc52ec..232a1ae1 100644 --- a/exampleCore/src/main/scala/ackcord/examplecore/Example.scala +++ b/exampleCore/src/main/scala/ackcord/examplecore/Example.scala @@ -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(