Skip to content

Commit

Permalink
Workaround dotty issue with meta annotations
Browse files Browse the repository at this point in the history
Workaround issue with annotations covered by
scala/scala3#12492, fixed with
scala/scala3#16445

This commit can be reverted as soon as the fix is released (according to
https://github.com/lampepfl/dotty/releases this is not yet the case)
  • Loading branch information
magro committed Jan 8, 2023
1 parent 4ea2356 commit c7c6f35
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion src/test/scala/io/ino/solrs/AsyncSolrClientFunSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import org.apache.solr.client.solrj.beans.Field
import org.scalatest.concurrent.Eventually.eventually
import org.scalatest.concurrent.PatienceConfiguration.Timeout

import scala.annotation.meta.field
import scala.jdk.CollectionConverters._
import scala.concurrent.duration._

Expand Down Expand Up @@ -202,9 +201,48 @@ class AsyncSolrClientFunSpec extends StandardFunSpec with RunningSolr {

}

/*
case class TestBean(@(Field @field) id: String,
@(Field @field) name: String,
@(Field @field) category: String,
@(Field @field) price: Float) {
def this() = this(null, null, null, 0)
}
*/

/* Can be replaced by the version above, once
https://github.com/lampepfl/dotty/issues/12492 respectively https://github.com/lampepfl/dotty/pull/16445
are released (see https://github.com/lampepfl/dotty/releases)
*/
class TestBean(_id: String, _name: String, _category: String, _price: Float) {
def this() = this(null, null, null, 0)

@Field
val id: String = _id
@Field
val name: String = _name
@Field
val category: String = _category
@Field
val price: Float = _price

override def equals(other: Any): Boolean = other match {
case that: TestBean =>
id == that.id &&
name == that.name &&
category == that.category &&
price == that.price
case _ => false
}

override def hashCode(): Int = {
val state = Seq(id, name, category, price)
state.map(_.hashCode()).foldLeft(0)((a, b) => 31 * a + b)
}

}

object TestBean {
def apply(id: String, name: String, category: String, price: Float): TestBean =
new TestBean(_id = id, _name = name, _category = category, _price = price)
}

0 comments on commit c7c6f35

Please sign in to comment.