Skip to content

Commit 685f8b0

Browse files
committed
Widen type of lifted expressions
1 parent 5dba756 commit 685f8b0

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

oolong-core/src/main/scala/oolong/AstParser.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,10 @@ private[oolong] class DefaultAstParser(using quotes: Quotes) extends AstParser {
163163
case '{ ($x: Option[_]).nonEmpty } =>
164164
QExpr.Exists(parse(x), QExpr.Constant(true))
165165

166-
case '{ ($x: Instant).isBefore($s) } =>
166+
case '{ ($x: Instant).isBefore($s: Instant) } =>
167167
QExpr.Lt(parse(x), parse(s))
168168

169-
case '{ ($x: Instant).isAfter($s) } =>
169+
case '{ ($x: Instant).isAfter($s: Instant) } =>
170170
QExpr.Gt(parse(x), parse(s))
171171

172172
case PropSelector(name, path) if name == paramName =>

oolong-mongo/src/main/scala/oolong/mongo/BsonUtils.scala

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,15 @@ private[oolong] object BsonUtils {
1919
case '{ $s: t } =>
2020
Expr.summon[BsonEncoder[t]] match {
2121
case Some(encoder) => '{ ${ encoder }.bson(${ s }) }
22-
case _ => report.errorAndAbort(s"Didn't find bson encoder for type ${TypeRepr.of[t].show}")
22+
case None if TypeRepr.of[t].isSingleton =>
23+
TypeRepr.of[t].widen.asType match {
24+
case '[tx] =>
25+
Expr.summon[BsonEncoder[tx]] match {
26+
case Some(encoder) => '{ ${ encoder }.bson(${ s.asExprOf[tx] }) }
27+
case _ => report.errorAndAbort(s"Didn't find bson encoder for type ${TypeRepr.of[t].widen.show}")
28+
}
29+
}
30+
case _ => report.errorAndAbort(s"Didn't find bson encoder for type ${TypeRepr.of[t].widen.show}")
2331
}
2432
}
25-
2633
}

oolong-mongo/src/test/scala/oolong/mongo/QuerySpec.scala

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,8 +1170,10 @@ class QuerySpec extends AnyFunSuite {
11701170

11711171
test("Instant.ifBefore is supported") {
11721172
case class InstantTest(field: Instant)
1173-
val q = query[InstantTest](_.field.isBefore(lift(Instant.parse("2020-01-01T00:00:00Z"))))
1174-
val repr = renderQuery[InstantTest](_.field.isBefore(lift(Instant.parse("2020-01-01T00:00:00Z"))))
1173+
1174+
val instant = Instant.parse("2020-01-01T00:00:00Z")
1175+
val q = query[InstantTest](_.field.isBefore(lift(instant)))
1176+
val repr = renderQuery[InstantTest](_.field.isBefore(lift(instant)))
11751177

11761178
test(
11771179
q,
@@ -1185,8 +1187,10 @@ class QuerySpec extends AnyFunSuite {
11851187

11861188
test("Instant.isAfter is supported") {
11871189
case class InstantTest(field: Instant)
1188-
val q = query[InstantTest](_.field.isAfter(lift(Instant.parse("2020-01-01T00:00:00Z"))))
1189-
val repr = renderQuery[InstantTest](_.field.isAfter(lift(Instant.parse("2020-01-01T00:00:00Z"))))
1190+
1191+
val instant = Instant.parse("2020-01-01T00:00:00Z")
1192+
val q = query[InstantTest](_.field.isAfter(lift(instant)))
1193+
val repr = renderQuery[InstantTest](_.field.isAfter(lift(instant)))
11901194

11911195
test(
11921196
q,

0 commit comments

Comments
 (0)