8000 Fix derivation of Reader[Any]/Writer[Any] instances on Scala 2.13 by shadaj · Pull Request #388 · shadaj/slinky · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix derivation of Reader[Any]/Writer[Any] instances on Scala 2.13 #388

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

Merged
merged 3 commits into from
Jun 21, 2020
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
+ Add facades for the `act` funcion in `react-test-renderer` [PR #376](https://github.com/shadaj/slinky/pull/376)

### Bug Fixes :bug:
+ Fix compilation errors on Scala 2.13 when `Any` is involved in `Props`/`State` types [PR #388](https://github.com/shadaj/slinky/pull/388)
+ Allow exporting external component definitions as instances of `ReactComponentClass` [PR #377](https://github.com/shadaj/slinky/pull/377)

### Breaking Changes :warning:
Expand Down
14 changes: 4 additions & 10 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ addCommandAlias(
)

val scala212 = "2.12.10"
val scala213 = "2.13.1"
val scala213 = "2.13.2"

ThisBuild / scalaVersion := scala212
ThisBuild / scalaVersion := scala213

lazy val slinky = project
.in(file("."))
Expand Down Expand Up @@ -72,14 +72,8 @@ lazy val librarySettings = Seq(
val g = "https://raw.githubusercontent.com/shadaj/slinky"
s"-P:scalajs:mapSourceURI:$a->$g/$githubVersion/${baseDirectory.value.getName}/"
},
scalacOptions --= Seq(
"-Ywarn-unused:params",
"-Ywarn-unused:patvars",
"-Ywarn-dead-code",
"-Xcheckinit",
"-Wunused:params",
"-Wunused:patvars",
"-Wdead-code"
scalacOptions ++= Seq(
"-Ywarn-unused:imports"
)
)

Expand Down
1 change: 1 addition & 0 deletions core/src/main/scala/slinky/core/BaseComponentWrapper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import slinky.readwrite.{Reader, Writer}
import scala.scalajs.js
import scala.scalajs.js.ConstructorTag

import scala.language.experimental.macros
import scala.reflect.macros.whitebox

final class KeyAndRefAddingStage[D](private val args: js.Array[js.Any]) extends AnyVal {
Expand Down
1 change: 1 addition & 0 deletions core/src/main/scala/slinky/core/ExternalComponent.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import slinky.readwrite.Writer

import scala.scalajs.js
import scala.scalajs.js.|
import scala.language.experimental.macros
import scala.reflect.macros.whitebox

final class BuildingComponent[E, R <: js.Object](private val args: js.Array[js.Any]) extends AnyVal {
Expand Down
1 change: 1 addition & 0 deletions core/src/main/scala/slinky/core/FunctionalComponent.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import slinky.readwrite.Reader
import slinky.core.facade.{ReactElement, ReactRaw, ReactRef}
import scala.scalajs.js

import scala.language.experimental.macros
import scala.reflect.macros.whitebox

final class KeyAddingStage(private val args: js.Array[js.Any]) extends AnyVal {
Expand Down
1 change: 1 addition & 0 deletions core/src/main/scala/slinky/core/annotations/react.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package slinky.core.annotations
import slinky.core._

import scala.annotation.compileTimeOnly
import scala.language.experimental.macros
import scala.reflect.macros.whitebox
import scala.scalajs.js

Expand Down
11 changes: 5 additions & 6 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ libraryDependencies ++= {

addSbtPlugin("com.jsuereth" % "sbt-pgp" % "2.0.1")

addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.9.2")
addSbtPlugin("com.dwijnand" % "sbt-dynver" % "4.0.0")
addSbtPlugin("org.jetbrains" % "sbt-idea-plugin" % "3.6.5")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.0")
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.9.16")
addSbtPlugin("io.github.davidgregory084" % "sbt-tpolecat" % "0.1.11")
addSbtPlugin("org.xerial.sbt" % "sbt-so 5D39 natype" % "3.9.2")
addSbtPlugin("com.dwijnand" % "sbt-dynver" % "4.0.0")
addSbtPlugin("org.jetbrains" % "sbt-idea-plugin" % "3.6.5")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.0")
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.9.16")
12 changes: 8 additions & 4 deletions readWrite/build.sbt
AE8F
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ Compile / sourceGenerators += Def.task {
| def write(p: P): js.Object
|}
|
|object Writer extends CoreWriters {
|trait FunctionWriters {
| ${gens.mkString("\n")}
|}""".stripMargin)
|}
|
|object Writer extends CoreWriters""".stripMargin)

out.close()
Seq(genFile)
Expand Down Expand Up @@ -87,9 +89,11 @@ Compile / sourceGenerators += Def.task {
| protected def forceRead(o: js.Object): P
|}
|
|object Reader extends CoreReaders {
|trait FunctionReaders {
| ${gens.mkString("\n")}
|}""".stripMargin)
}
|
|object Reader extends CoreReaders""".stripMargin)

out.close()
Seq(genFile)
Expand Down
3 changes: 2 additions & 1 deletion readWrite/src/main/scala/slinky/readwrite/CoreReaders.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import scala.concurrent.ExecutionContext.Implicits.global

import scala.reflect.ClassTag
import scala.reflect.macros.whitebox
import scala.language.experimental.macros

@compileTimeOnly("Deferred readers are used to handle recursive structures")
final class DeferredReader[T, Term] extends Reader[T] {
Expand Down Expand Up @@ -94,7 +95,7 @@ class MacroReadersImpl(_c: whitebox.Context) extends GenericDeriveImpl(_c) {
def createFallback(forType: c.Type) = q"_root_.slinky.readwrite.Reader.fallback[$forType]"
}

trait CoreReaders extends MacroReaders with FallbackReaders {
trait CoreReaders extends MacroReaders with FallbackReaders with FunctionReaders {
implicit def jsAnyReader[T <: js.Any]: Reader[T] = _.asInstanceOf[T]

implicit val unitReader: Reader[Unit] = _ => ()
Expand Down
3 changes: 2 additions & 1 deletion readWrite/src/main/scala/slinky/readwrite/CoreWriters.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import scala.scalajs.js
import scala.scalajs.js.|
import scala.concurrent.ExecutionContext.Implicits.global
import scala.reflect.macros.whitebox
import scala.language.experimental.macros

@compileTimeOnly("Deferred writers are used to handle recursive structures")
final class DeferredWriter[T, Term] extends Writer[T] {
Expand Down Expand Up @@ -92,7 +93,7 @@ class MacroWritersImpl(_c: whitebox.Context) extends GenericDeriveImpl(_c) {
def createFallback(forType: Type) = q"_root_.slinky.readwrite.Writer.fallback[$forType]"
}

trait CoreWriters extends MacroWriters with FallbackWriters {
trait CoreWriters extends MacroWriters with FallbackWriters with FunctionWriters {
implicit def jsAnyWriter[T <: js.Any]: Writer[T] = _.asInstanceOf[js.Object]

implicit val unitWriter: Writer[Unit] = _ => js.Dynamic.literal()
Expand Down
4 changes: 4 additions & 0 deletions tests/src/test/scala/slinky/core/ReaderWriterTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,10 @@ class ReaderWriterTest extends AnyFunSuite {
readWrittenSame[ContainingPrivateType.ToRead](ContainingPrivateType.TestInstance, true)
}

test("Read/write - any") {
readWrittenSame[Any](123, true)
}

test("Reading empty object uses default parameter values when available") {
assert(implicitly[Reader[ClassWithDefault]].read(js.Dynamic.literal()).a == 5)
}
Expand Down
0