Skip to content

Commit 5c65913

Browse files
committed
[uri-2] explicitly type Exprs
1 parent 208bd02 commit 5c65913

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

UriParser/src/main/scala-2/MacroImpl.scala

+10-10
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ object MacroImpl {
1616
import c.universe.Quasiquote
1717

1818
implicit val thisCToExpr = typeclass.ToExprMapping.forContext(c)
19-
val constExpr:Function1[String, c.Expr[String]] = {x => c.Expr(c.universe.Literal(c.universe.Constant(x)))}
20-
val constNullExpr:c.Expr[Null] = c.Expr(c.universe.Literal(c.universe.Constant(null)))
21-
val constNegOneExpr:c.Expr[Int] = c.Expr(c.universe.Literal(c.universe.Constant(-1)))
19+
val constExpr:Function1[String, c.Expr[String]] = {x => c.Expr[String](c.universe.Literal(c.universe.Constant(x)))}
20+
val constNullExpr:c.Expr[Null] = c.Expr[Null](c.universe.Literal(c.universe.Constant(null)))
21+
val constNegOneExpr:c.Expr[Int] = c.Expr[Int](c.universe.Literal(c.universe.Constant(-1)))
2222
def parseByteHex(x:(Char, Char)):Int = java.lang.Integer.parseInt(s"${x._1}${x._2}", 16)
2323

2424
val hexChar:Interpolator[Char] = charWhere(c => '0' <= c && c <= '9' || 'a' <= c && c <= 'f' || 'A' <= c && c <= 'F').opaque("hexChar")
@@ -101,14 +101,14 @@ object MacroImpl {
101101
}
102102
/* Luckily, the URI constructor seems to be able to surround v6 addresses in brackets automatically, so that we don't have to */
103103
val variableInetAddress:Interpolator[c.Expr[String]] = ofType(c.typeTag[java.net.InetAddress])
104-
.map((x, _:c.type) => c.Expr(q"$x.getHostName()"))
104+
.map((x, _:c.type) => c.Expr[String](q"$x.getHostName()"))
105105
variableInetAddress <|> literalIpv4 <|> literalIpv6 <|> literalName
106106
}
107107

108108
val port:Interpolator[c.Expr[Int]] = {
109109
val literal:Interpolator[c.Expr[Int]] = digitChar.repeat(1)
110110
.map({(x, _:c.type) => java.lang.Integer.parseInt(x)})
111-
.map({(x, _:c.type) => c.Expr(c.universe.Literal(c.universe.Constant(x)))})
111+
.map({(x, _:c.type) => c.Expr[Int](c.universe.Literal(c.universe.Constant(x)))})
112112
.opaque("Port")
113113
val literalEmpty:Interpolator[c.Expr[Int]] = isString("").map({(_:Unit, _:c.type) => constNegOneExpr})
114114
val variable:Interpolator[c.Expr[Int]] = ofType[Int]
@@ -117,11 +117,11 @@ object MacroImpl {
117117

118118
val hostPort:Interpolator[(c.Expr[String], c.Expr[Int])] = {
119119
val literal = host <~> (isString(":") <~> port)
120-
.optionally().map((x, _:c.type) => x.getOrElse(c.Expr(q"-1")))
120+
.optionally().map((x, _:c.type) => x.getOrElse(constNegOneExpr))
121121
val SockAddr = ofType(c.typeTag[java.net.InetSocketAddress])
122122
.map((x, _:c.type) => (
123-
c.Expr(q"$x.getHostString()"),
124-
c.Expr(q"$x.getPort()")
123+
c.Expr[String](q"$x.getHostString()"),
124+
c.Expr[Int](q"$x.getPort()")
125125
))
126126
SockAddr <|> literal
127127
}
@@ -271,7 +271,7 @@ object MacroImpl {
271271
}) <|>
272272
(opaquePart <~> fragment).map({(x, _:c.type) =>
273273
x match {case (ssp, frag) =>
274-
c.Expr(q"""
274+
c.Expr[URI](q"""
275275
new java.net.URI(
276276
$scheme,
277277
$ssp,
@@ -310,7 +310,7 @@ object MacroImpl {
310310
val resolvedUri:Interpolator[c.Expr[URI]] = {
311311
(ofType[URI] <~> relativeUri).map({(params, _:c.type) =>
312312
val (base, resolvant) = params
313-
c.Expr(q"$base.resolve($resolvant)")
313+
c.Expr[URI](q"$base.resolve($resolvant)")
314314
})
315315
}
316316

0 commit comments

Comments
 (0)