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

Make Quill compatible with Scala 2.12.2 #770

Merged
merged 1 commit into from May 12, 2017
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 9 additions & 10 deletions build.sbt
Expand Up @@ -241,14 +241,19 @@ lazy val commonSettings = ReleasePlugin.extraReleaseCommands ++ Seq(
"-encoding", "UTF-8",
"-feature",
"-unchecked",
"-Xlint",
"-Yno-adapted-args",
"-Ywarn-dead-code",
"-Ywarn-numeric-widen",
"-Ywarn-value-discard",
"-Xfuture",
"-Ywarn-unused-import"
"-Xfuture"
),
scalacOptions ++= {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, 11)) => Seq("-Xlint", "-Ywarn-unused-import")
case Some((2, 12)) => Seq("-Xlint:-unused,_", "-Ywarn-unused:imports")
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Now it should be more convenient

case _ => Seq()
}
},
concurrentRestrictions in Global += Tags.limit(Tags.Test, 1),
releasePublishArtifactsAction := PgpKeys.publishSigned.value,
scoverage.ScoverageKeys.coverageMinimum := 96,
Expand Down Expand Up @@ -318,10 +323,4 @@ lazy val commonSettings = ReleasePlugin.extraReleaseCommands ++ Seq(
<url>http://github.com/fwbrasil/</url>
</developer>
</developers>)
) ++ update2_12

lazy val update2_12 = Seq(
scalacOptions -= (
if (scalaVersion.value.startsWith("2.12.")) "-Xfatal-warnings" else ""
)
)
)
8 changes: 4 additions & 4 deletions build/build.sh
Expand Up @@ -22,16 +22,16 @@ then
git checkout master || git checkout -b master
git reset --hard origin/master
git push --delete origin website
sbt tut 'release with-defaults'
sbt tut 'release cross with-defaults'
elif [[ $TRAVIS_BRANCH == "master" ]]
then
sbt clean coverage test tut coverageReport coverageAggregate checkUnformattedFiles
sbt clean ++2.12.2 test ++2.11.11 coverage test tut coverageReport coverageAggregate checkUnformattedFiles
sbt coverageOff publish
else
sbt clean coverage test tut coverageReport coverageAggregate checkUnformattedFiles
sbt clean ++2.12.2 test ++2.11.11 coverage test tut coverageReport coverageAggregate checkUnformattedFiles
echo "version in ThisBuild := \"$TRAVIS_BRANCH-SNAPSHOT\"" > version.sbt
sbt coverageOff publish
fi
else
sbt clean coverage test tut coverageReport coverageAggregate checkUnformattedFiles
sbt clean ++2.12.2 test ++2.11.11 coverage test tut coverageReport coverageAggregate checkUnformattedFiles
fi
Expand Up @@ -5,7 +5,7 @@ import java.time.{ LocalDate, LocalDateTime }
import io.getquill.context.sql.EncodingSpec

import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.{ Await, ExecutionContext }
import scala.concurrent.Await
import scala.concurrent.duration.Duration
import java.util.Date

Expand Down Expand Up @@ -143,7 +143,7 @@ class MysqlAsyncEncodingSpec extends EncodingSpec {

"encodes custom type inside singleton object" in {
object Singleton {
def apply()(implicit c: TestContext, ec: ExecutionContext) = {
def apply()(implicit c: TestContext) = {
import c._
for {
_ <- c.run(query[EncodingTestEntity].delete)
Expand Down
Expand Up @@ -5,7 +5,7 @@ import java.time.{ LocalDate, LocalDateTime }
import io.getquill.context.sql.EncodingSpec

import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.{ Await, ExecutionContext }
import scala.concurrent.Await
import scala.concurrent.duration.Duration
import java.util.Date
import java.util.UUID
Expand Down Expand Up @@ -111,7 +111,7 @@ class PostgresAsyncEncodingSpec extends EncodingSpec {

"encodes custom type inside singleton object" in {
object Singleton {
def apply()(implicit c: TestContext, ec: ExecutionContext) = {
def apply()(implicit c: TestContext) = {
import c._
for {
_ <- c.run(query[EncodingTestEntity].delete)
Expand Down
Expand Up @@ -5,7 +5,6 @@ import scala.util.Try
import com.typesafe.config.Config
import com.typesafe.config.ConfigValueType
import java.lang.reflect.Method
import scala.collection.JavaConversions._
import scala.collection.JavaConverters._
import com.datastax.driver.core.Cluster

Expand All @@ -15,7 +14,7 @@ object ClusterBuilder {
set(Cluster.builder, cfg)

private def set[T](instance: T, cfg: Config): T = {
for (key <- cfg.entrySet.map(_.getKey.split('.').head)) {
for (key <- cfg.entrySet.asScala.map(_.getKey.split('.').head)) {

def tryMethod(m: Method) =
m.getParameterTypes.toList match {
Expand Down
10 changes: 5 additions & 5 deletions quill-core/src/main/scala/io/getquill/dsl/MetaDsl.scala
Expand Up @@ -22,19 +22,19 @@ trait MetaDsl extends MetaDslLowPriorityImplicits {
def insertMeta[T](exclude: (T => Any)*): InsertMeta[T] = macro MetaDslMacro.insertMeta[T]

trait SchemaMeta[T] {
val entity: Quoted[EntityQuery[T]]
def entity: Quoted[EntityQuery[T]]
}

trait QueryMeta[T] {
val expand: Quoted[Query[T] => Query[_]]
val extract: ResultRow => T
def expand: Quoted[Query[T] => Query[_]]
def extract: ResultRow => T
}

trait UpdateMeta[T] {
val expand: Quoted[(EntityQuery[T], T) => Update[T]]
def expand: Quoted[(EntityQuery[T], T) => Update[T]]
}

trait InsertMeta[T] {
val expand: Quoted[(EntityQuery[T], T) => Insert[T]]
def expand: Quoted[(EntityQuery[T], T) => Insert[T]]
}
}
20 changes: 12 additions & 8 deletions quill-core/src/main/scala/io/getquill/dsl/MetaDslMacro.scala
Expand Up @@ -12,10 +12,10 @@ class MetaDslMacro(val c: MacroContext) {
c.untypecheck {
q"""
new ${c.prefix}.SchemaMeta[$t] {
val entity =
${c.prefix}.quote {
${c.prefix}.querySchema[$t]($entity, ..$columns)
}
private[this] val _entity = ${c.prefix}.quote {
${c.prefix}.querySchema[$t]($entity, ..$columns)
}
def entity = _entity
}
"""
}
Expand All @@ -24,7 +24,8 @@ class MetaDslMacro(val c: MacroContext) {
c.untypecheck {
q"""
new ${c.prefix}.QueryMeta[$t] {
val expand = $expand
private[this] val _expand = $expand
def expand = _expand
val extract =
(r: ${c.prefix}.ResultRow) => $extract(implicitly[${c.prefix}.QueryMeta[$r]].extract(r))
}
Expand All @@ -41,7 +42,8 @@ class MetaDslMacro(val c: MacroContext) {
val value = this.value("Decoder", t.tpe)
q"""
new ${c.prefix}.QueryMeta[$t] {
val expand = ${expandQuery[T](value)}
private[this] val _expanded = ${expandQuery[T](value)}
def expand = _expanded
val extract = ${extract[T](value)}
}
"""
Expand All @@ -57,8 +59,9 @@ class MetaDslMacro(val c: MacroContext) {
if (t.tpe.typeSymbol.isClass && t.tpe.typeSymbol.asClass.isCaseClass) {
q"""
new ${c.prefix}.SchemaMeta[$t] {
val entity =
private[this] val _entity =
${c.prefix}.quote(${c.prefix}.querySchema[$t](${t.tpe.typeSymbol.name.decodedName.toString}))
def entity = _entity
}
"""
} else {
Expand Down Expand Up @@ -122,8 +125,9 @@ class MetaDslMacro(val c: MacroContext) {
c.untypecheck {
q"""
new ${c.prefix}.${TypeName(method.capitalize + "Meta")}[$t] {
val expand =
private[this] val _expand =
${c.prefix}.quote((q: ${c.prefix}.EntityQuery[$t], value: $t) => q.${TermName(method)}(..$assignments))
def expand = _expand
}
"""
}
Expand Down
Expand Up @@ -4,11 +4,11 @@ import scala.math.BigDecimal.double2bigDecimal
import scala.math.BigDecimal.int2bigDecimal
import scala.math.BigDecimal.javaBigDecimal2bigDecimal
import scala.math.BigDecimal.long2bigDecimal

import io.getquill.Spec
import io.getquill.ast.{ Query => _, _ }
import io.getquill.testContext._
import io.getquill.context.ValueClass
import io.getquill.util.Messages

case class CustomAnyValue(i: Int) extends AnyVal
case class EmbeddedValue(s: String, i: Int) extends Embedded
Expand Down Expand Up @@ -726,6 +726,7 @@ class QuotationSpec extends Spec {
quote(unquote(q)).ast match {
case Function(params, Tuple(values)) =>
values mustEqual params
case _ => Messages.fail("Should not happen")
}
}
"java to scala" in {
Expand All @@ -739,6 +740,7 @@ class QuotationSpec extends Spec {
quote(unquote(q)).ast match {
case Function(params, Tuple(values)) =>
values mustEqual params
case _ => Messages.fail("Should not happen")
}
}
}
Expand Down Expand Up @@ -847,17 +849,18 @@ class QuotationSpec extends Spec {
l.encoder mustEqual intEncoder
}
"property" in {
case class Test(a: String)
val t = Test("a")
case class TestEntity(a: String)
val t = TestEntity("a")
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I forgot detailed error however it is connected with suspicious shadowing of generated class name or something like that

val q = quote(lift(t.a))

val l = q.liftings.`t.a`
l.value mustEqual t.a
l.encoder mustEqual stringEncoder
}
"abritrary" in {
val q = quote(lift(String.valueOf(1)))
q.liftings.`java.this.lang.String.valueOf(1)`.value mustEqual String.valueOf(1)
class A { def x = 1 }
val q = quote(lift(new A().x))
q.liftings.`new A().x`.value mustEqual new A().x
Copy link
Collaborator Author

@mosyp mosyp May 12, 2017

Choose a reason for hiding this comment

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

@fwbrasil I hope this works for such test case, since using static calls as before is prohibit fr cross compilation

}
"duplicate" in {
val i = 1
Expand Down