Skip to content

Commit

Permalink
Reduce compiler warnings (#816)
Browse files Browse the repository at this point in the history
  • Loading branch information
RustedBones authored Aug 23, 2023
1 parent 1955987 commit 993ad92
Show file tree
Hide file tree
Showing 30 changed files with 84 additions and 101 deletions.
4 changes: 2 additions & 2 deletions avro/src/main/scala/magnolify/avro/AvroType.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package magnolify.avro

import magnolia1._
import magnolify.shared._
import magnolify.shared.{doc => _, _}
import magnolify.shims.FactoryCompat
import org.apache.avro.generic.GenericData.EnumSymbol
import org.apache.avro.generic._
Expand Down Expand Up @@ -216,7 +216,7 @@ object AvroField {
override def to(v: String)(cm: CaseMapper): String = v
}

@nowarn("msg=parameter value lp in method afEnum is never used")
@nowarn("msg=parameter lp in method afEnum is never used")
implicit def afEnum[T](implicit et: EnumType[T], lp: shapeless.LowPriority): AvroField[T] =
// Avro 1.9+ added a type parameter for `GenericEnumSymbol`, breaking 1.8 compatibility
// Some reader, i.e. `AvroParquetReader` reads enums as `Utf8`
Expand Down
4 changes: 2 additions & 2 deletions avro/src/test/scala/magnolify/avro/AvroTypeSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class AvroTypeSuite extends MagnolifySuite {
val tpe = ensureSerializable(t)
val copier = new Copier(tpe.schema)
property(className[T]) {
Prop.forAll { t: T =>
Prop.forAll { (t: T) =>
val r = tpe(t)
val rCopy = copier(r)
val copy = tpe(rCopy)
Expand All @@ -111,7 +111,7 @@ class AvroTypeSuite extends MagnolifySuite {
// validate that the string schema contains the correct logical type
val jf = new JsonFactory
val om = new ObjectMapper(jf)
val tree: JsonNode = om.readTree(jf.createParser(schema.toString()))
val tree = om.readTree[JsonNode](jf.createParser(schema.toString()))
val sf = tree.get("fields").elements().asScala.find(_.get("name").asText() == fieldName)
assert(sf.isDefined, s"schema field $fieldName is undefined")
val slt = sf.flatMap(f => Try(f.get("type").get("logicalType").asText()).toOption)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ class TableRowTypeSuite extends MagnolifySuite {
private def test[T: Arbitrary: ClassTag](implicit t: TableRowType[T], eq: Eq[T]): Unit = {
val tpe = ensureSerializable(t)
// FIXME: test schema
tpe.schema
tpe.schema: Unit
property(className[T]) {
Prop.forAll { t: T =>
Prop.forAll { (t: T) =>
val r = tpe(t)
val copy1 = tpe(r)
val copy2 = tpe(mapper.readValue(mapper.writeValueAsString(r), classOf[TableRow]))
Expand Down
8 changes: 3 additions & 5 deletions bigtable/src/main/scala/magnolify/bigtable/BigtableType.scala
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,12 @@ object BigtableField {

private def primitive[T](
capacity: Int
)(f: ByteBuffer => T)(g: (ByteBuffer, T) => Unit): Primitive[T] = new Primitive[T] {
)(f: ByteBuffer => T)(g: (ByteBuffer, T) => ByteBuffer): Primitive[T] = new Primitive[T] {
override val size: Option[Int] = Some(capacity)
override def fromByteString(v: ByteString): T = f(v.asReadOnlyByteBuffer())
override def toByteString(v: T): ByteString = {
val bb = ByteBuffer.allocate(capacity)
g(bb, v)
ByteString.copyFrom(bb.array())
ByteString.copyFrom(g(bb, v).array())
}
}

Expand All @@ -221,8 +220,7 @@ object BigtableField {
implicit val btfBoolean: Primitive[Boolean] = from[Byte](_ == 1)(if (_) 1 else 0)
implicit val btfUUID: Primitive[UUID] =
primitive[UUID](16)(bb => new UUID(bb.getLong, bb.getLong)) { (bb, uuid) =>
bb.putLong(uuid.getMostSignificantBits)
bb.putLong(uuid.getLeastSignificantBits)
bb.putLong(uuid.getMostSignificantBits).putLong(uuid.getLeastSignificantBits)
}

implicit val btfByteString: Primitive[ByteString] = new Primitive[ByteString] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class BigtableTypeSuite extends MagnolifySuite {
private def test[T: Arbitrary: ClassTag](implicit t: BigtableType[T], eq: Eq[T]): Unit = {
val tpe = ensureSerializable(t)
property(className[T]) {
Prop.forAll { t: T =>
Prop.forAll { (t: T) =>
val mutations = tpe(t, "cf")
val row = BigtableType.mutationsToRow(ByteString.EMPTY, mutations)
val copy = tpe(row, "cf")
Expand Down
53 changes: 28 additions & 25 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -179,31 +179,32 @@ lazy val keepExistingHeader =
val commonSettings = Seq(
tlFatalWarnings := false,
tlJdkRelease := Some(8),
scalacOptions ++= {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((3, _)) =>
Seq(
// required by magnolia for accessing default values
"-Xretain-trees",
// tolerate some nested macro expansion
"-Ymax-inlines",
"64"
)
case Some((2, 13)) =>
Seq(
// silence warnings
"-Wmacros:after",
"-Wconf:cat=unused-imports&origin=scala\\.collection\\.compat\\..*:s" +
",cat=unused-imports&origin=magnolify\\.shims\\..*:s"
)
case Some((2, 12)) =>
Seq(
"-Ywarn-macros:after"
)
case _ =>
Seq.empty
}
},
scalacOptions ++= (CrossVersion.partialVersion(scalaVersion.value) match {
case Some((3, _)) =>
Seq(
// required by magnolia for accessing default values
"-Xretain-trees",
// tolerate some nested macro expansion
"-Ymax-inlines",
"64"
)
case Some((2, 13)) =>
Seq(
"-Wmacros:after",
// silence warnings
"-Wconf:cat=unused-imports&origin=scala\\.collection\\.compat\\..*:s" +
",cat=unused-imports&origin=magnolify\\.shims\\..*:s" +
",cat=unused-imports&origin=magnolify\\.scalacheck\\.MoreCollectionsBuildable\\..*:s"
)
case Some((2, 12)) =>
Seq(
"-Ywarn-macros:after",
// silence warnings
"-Wconf:cat=unused-params:s"
)
case _ =>
Seq.empty
}),
headerLicense := Some(HeaderLicense.ALv2(currentYear.toString, organizationName.value)),
headerMappings ++= Map(
HeaderFileType.scala -> keepExistingHeader,
Expand Down Expand Up @@ -479,6 +480,8 @@ lazy val tensorflow = project
"com.google.protobuf" % "protobuf-java" % protobufVersion % ProtobufConfig,
"org.tensorflow" % "tensorflow-core-api" % tensorflowVersion % Provided
),
// remove compilation warnings for generated java files
javacOptions ~= { _.filterNot(_ == "-Xlint:all") },
// tensorflow metadata protos are not packaged into a jar. Manually extract them as external
Compile / PB.protoSources += target.value / s"metadata-$tensorflowMetadataVersion",
Compile / PB.unpackDependencies := {
Expand Down
22 changes: 0 additions & 22 deletions cats/src/main/scala-2.12/magnolify/cats/semiauto/package.scala

This file was deleted.

20 changes: 10 additions & 10 deletions cats/src/main/scala/magnolify/cats/CatsMacros.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,70 +21,70 @@ import scala.annotation.nowarn

private object CatsMacros {

@nowarn("msg=parameter value lp in method genShowMacro is never used")
@nowarn("msg=parameter lp in method genShowMacro is never used")
def genShowMacro[T: c.WeakTypeTag](c: whitebox.Context)(lp: c.Tree): c.Tree = {
import c.universe._
val wtt = weakTypeTag[T]
q"""_root_.magnolify.cats.semiauto.ShowDerivation.apply[$wtt]"""
}

@nowarn("msg=parameter value lp in method genEqMacro is never used")
@nowarn("msg=parameter lp in method genEqMacro is never used")
def genEqMacro[T: c.WeakTypeTag](c: whitebox.Context)(lp: c.Tree): c.Tree = {
import c.universe._
val wtt = weakTypeTag[T]
q"""_root_.magnolify.cats.semiauto.EqDerivation.apply[$wtt]"""
}

@nowarn("msg=parameter value lp in method genHashMacro is never used")
@nowarn("msg=parameter lp in method genHashMacro is never used")
def genHashMacro[T: c.WeakTypeTag](c: whitebox.Context)(lp: c.Tree): c.Tree = {
import c.universe._
val wtt = weakTypeTag[T]
q"""_root_.magnolify.cats.semiauto.HashDerivation.apply[$wtt]"""
}

@nowarn("msg=parameter value lp in method genSemigroupMacro is never used")
@nowarn("msg=parameter lp in method genSemigroupMacro is never used")
def genSemigroupMacro[T: c.WeakTypeTag](c: whitebox.Context)(lp: c.Tree): c.Tree = {
import c.universe._
val wtt = weakTypeTag[T]
q"""_root_.magnolify.cats.semiauto.SemigroupDerivation.apply[$wtt]"""
}

@nowarn("msg=parameter value lp in method genMonoidMacro is never used")
@nowarn("msg=parameter lp in method genMonoidMacro is never used")
def genMonoidMacro[T: c.WeakTypeTag](c: whitebox.Context)(lp: c.Tree): c.Tree = {
import c.universe._
val wtt = weakTypeTag[T]
q"""_root_.magnolify.cats.semiauto.MonoidDerivation.apply[$wtt]"""
}

@nowarn("msg=parameter value lp in method genCommutativeSemigroupMacro is never used")
@nowarn("msg=parameter lp in method genCommutativeSemigroupMacro is never used")
def genCommutativeSemigroupMacro[T: c.WeakTypeTag](c: whitebox.Context)(lp: c.Tree): c.Tree = {
import c.universe._
val wtt = weakTypeTag[T]
q"""_root_.magnolify.cats.semiauto.CommutativeSemigroupDerivation.apply[$wtt]"""
}

@nowarn("msg=parameter value lp in method genCommutativeMonoidMacro is never used")
@nowarn("msg=parameter lp in method genCommutativeMonoidMacro is never used")
def genCommutativeMonoidMacro[T: c.WeakTypeTag](c: whitebox.Context)(lp: c.Tree): c.Tree = {
import c.universe._
val wtt = weakTypeTag[T]
q"""_root_.magnolify.cats.semiauto.CommutativeMonoidDerivation.apply[$wtt]"""
}

@nowarn("msg=parameter value lp in method genGroupMacro is never used")
@nowarn("msg=parameter lp in method genGroupMacro is never used")
def genGroupMacro[T: c.WeakTypeTag](c: whitebox.Context)(lp: c.Tree): c.Tree = {
import c.universe._
val wtt = weakTypeTag[T]
q"""_root_.magnolify.cats.semiauto.GroupDerivation.apply[$wtt]"""
}

@nowarn("msg=parameter value lp in method genCommutativeGroupMacro is never used")
@nowarn("msg=parameter lp in method genCommutativeGroupMacro is never used")
def genCommutativeGroupMacro[T: c.WeakTypeTag](c: whitebox.Context)(lp: c.Tree): c.Tree = {
import c.universe._
val wtt = weakTypeTag[T]
q"""_root_.magnolify.cats.semiauto.CommutativeGroupDerivation.apply[$wtt]"""
}

@nowarn("msg=parameter value lp in method genBandMacro is never used")
@nowarn("msg=parameter lp in method genBandMacro is never used")
def genBandMacro[T: c.WeakTypeTag](c: whitebox.Context)(lp: c.Tree): c.Tree = {
import c.universe._
val wtt = weakTypeTag[T]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import cats.kernel.Band
import magnolia1._

import scala.annotation.implicitNotFound
import scala.collection.compat._

object BandDerivation {
type Typeclass[T] = Band[T]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import cats.kernel.CommutativeGroup
import magnolia1._

import scala.annotation.implicitNotFound
import scala.collection.compat._

object CommutativeGroupDerivation {
type Typeclass[T] = CommutativeGroup[T]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import cats.kernel.CommutativeMonoid
import magnolia1._

import scala.annotation.implicitNotFound
import scala.collection.compat._

object CommutativeMonoidDerivation {
type Typeclass[T] = CommutativeMonoid[T]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import cats.kernel.CommutativeSemigroup
import magnolia1._

import scala.annotation.implicitNotFound
import scala.collection.compat._

object CommutativeSemigroupDerivation {
type Typeclass[T] = CommutativeSemigroup[T]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import cats.Group
import magnolia1._

import scala.annotation.implicitNotFound
import scala.collection.compat._

object GroupDerivation {
type Typeclass[T] = Group[T]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class ShowDerivationSuite extends MagnolifySuite {
include(ContravariantTests[Show].contravariant[MiniInt, Int, Boolean].all, s"$name.")

property(s"$name.fullName") {
Prop.forAll { v: T =>
Prop.forAll { (v: T) =>
val fullName = v.getClass.getCanonicalName.stripSuffix("$")
val s = show.show(v)
s.startsWith(s"$fullName {") && s.endsWith("}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class EntityTypeSuite extends MagnolifySuite {
private def test[T: Arbitrary: ClassTag](implicit t: EntityType[T], eq: Eq[T]): Unit = {
val tpe = ensureSerializable(t)
property(className[T]) {
Prop.forAll { t: T =>
Prop.forAll { (t: T) =>
val r = tpe(t)
val copy = tpe(r)
eq.eqv(t, copy)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class FunnelDerivationSuite extends MagnolifySuite {
}
}
property(s"$name.consistency") {
Prop.forAll { x: T => toBytes(x, fnl) == toBytes(x, fnl) }
Prop.forAll((x: T) => toBytes(x, fnl) == toBytes(x, fnl))
}
}

Expand Down
2 changes: 1 addition & 1 deletion neo4j/src/test/scala/magnolify/neo4j/ValueTypeSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class ValueTypeSuite extends MagnolifySuite {
private def test[T: Arbitrary: ClassTag](implicit t: ValueType[T], eq: Eq[T]): Unit = {
val tpe = ensureSerializable(t)
property(className[T]) {
Prop.forAll { t: T =>
Prop.forAll { (t: T) =>
val v = tpe(t)
val copy = tpe(v)
eq.eqv(t, copy)
Expand Down
5 changes: 3 additions & 2 deletions parquet/src/main/scala/magnolify/parquet/ParquetType.scala
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ object ParquetType {

override def init(context: hadoop.InitContext): hadoop.ReadSupport.ReadContext = {
if (parquetType == null) {
parquetType = SerializationUtils.fromBase64(context.getConfiguration.get(ReadTypeKey))
parquetType =
SerializationUtils.fromBase64[ParquetType[T]](context.getConfiguration.get(ReadTypeKey))
}

val metadata = context.getKeyValueMetadata
Expand Down Expand Up @@ -174,7 +175,7 @@ object ParquetType {

override def init(configuration: Configuration): hadoop.WriteSupport.WriteContext = {
if (parquetType == null) {
parquetType = SerializationUtils.fromBase64(configuration.get(WriteTypeKey))
parquetType = SerializationUtils.fromBase64[ParquetType[T]](configuration.get(WriteTypeKey))
}

val schema = Schema.message(parquetType.schema)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ class AvroParquetSuite extends MagnolifySuite {
eq: Eq[T]
): Unit = {
// Ensure serializable even after evaluation of `schema` and `avroSchema`
val parquetSchema = tpe.schema
val avroSchema = tpe.avroSchema
tpe.schema: Unit
tpe.avroSchema: Unit
val pt = ensureSerializable(tpe)

property(s"$name.avro2parquet") {
Prop.forAll { t: T =>
Prop.forAll { (t: T) =>
val r = at(t)

val out = new TestOutputFile
Expand All @@ -91,7 +91,7 @@ class AvroParquetSuite extends MagnolifySuite {
}

property(s"$name.parquet2avro") {
Prop.forAll { t: T =>
Prop.forAll { (t: T) =>
val out = new TestOutputFile
val writer = pt.writeBuilder(out).build()
writer.write(t)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ class ParquetTypeSuite extends MagnolifySuite {
eq: Eq[T]
): Unit = {
// Ensure serializable even after evaluation of `schema`
val parquetSchema = t.schema
t.schema: Unit
val tpe = ensureSerializable(t)

property(className[T]) {
Prop.forAll { t: T =>
Prop.forAll { (t: T) =>
val out = new TestOutputFile
val writer = tpe.writeBuilder(out).build()
writer.write(t)
Expand Down Expand Up @@ -217,7 +217,7 @@ class TestInputFile(ba: Array[Byte]) extends InputFile {
override def getPos: Long = (ba.length - bais.available()).toLong
override def seek(newPos: Long): Unit = {
bais.reset()
bais.skip(newPos)
bais.skip(newPos): Unit
}
}
}
Expand Down
Loading

0 comments on commit 993ad92

Please sign in to comment.