Skip to content

Commit

Permalink
fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
YuriyMazepin committed Jun 15, 2023
1 parent acd6d65 commit 4ab93f8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
16 changes: 8 additions & 8 deletions proto/src/main/scala-3/BuildCodec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ trait BuildCodec extends Common:
'{
if ${Select.unique(getter, "isDefined").asExprOf[Boolean]} then {
${os}.writeUInt32NoTag(${Expr(field.tag)})
${writeFun(os, tpe, getterOption)}
${writeFun(os, tpe.asMatchable, getterOption)}
}
}
)
Expand Down Expand Up @@ -99,7 +99,7 @@ trait BuildCodec extends Common:
.appliedTo(
'{ (v: t) => {
${os}.writeUInt32NoTag(${Expr(field.tag)})
${writeFun(os, tpe1, 'v.asTerm)}
${writeFun(os, tpe1.asMatchable, 'v.asTerm)}
}
}.asTerm
).asExprOf[Unit]
Expand All @@ -114,7 +114,7 @@ trait BuildCodec extends Common:
, '{ ${os}.writeUInt32NoTag(${sizeRef.asExprOf[Int]}) }
, Select.unique(getter, "foreach")
.appliedToType(unitLiteral.tpe)
.appliedTo('{ (v: t) => ${writeFun(os, tpe1, 'v.asTerm)} }.asTerm)
.appliedTo('{ (v: t) => ${writeFun(os, tpe1.asMatchable, 'v.asTerm)} }.asTerm)
.asExprOf[Unit]
// a.field.foreach((v: V) => writeFun(os, v))
)
Expand Down Expand Up @@ -164,7 +164,7 @@ trait BuildCodec extends Common:
val getter: Term = field.getter(a.asTerm)
val getterOption: Term = Select.unique(getter, "get")//getterOptionTerm(a, field)
if (tpe.isCommonType) then
val fun = sizeFun(tpe, getterOption)
val fun = sizeFun(tpe.asMatchable, getterOption)
val sum = '{ ${Expr(CodedOutputStream.computeTagSize(field.num))} + ${fun} }
val incrementSize = increment(sizeAcc, sum)
val isDefined = Select.unique(getter, "isDefined")
Expand Down Expand Up @@ -203,7 +203,7 @@ trait BuildCodec extends Common:
.appliedToType(unitLiteral.tpe)
.appliedTo(
'{ (v: t) =>
${ increment(sizeRef, '{ ${sizeFun(tpe1, 'v.asTerm)} + tagSize }).asExprOf[Unit] }
${ increment(sizeRef, '{ ${sizeFun(tpe1.asMatchable, 'v.asTerm)} + tagSize }).asExprOf[Unit] }
}.asTerm
).asExpr
} // a.field.foreach((v: V) => sizeRef = sizeRef + sizeFun(v) + tagSize)
Expand All @@ -217,7 +217,7 @@ trait BuildCodec extends Common:
.appliedToType(unitLiteral.tpe)
.appliedTo(
'{ (v: t) =>
${ increment(sizeRef, sizeFun(tpe1, 'v.asTerm)).asExprOf[Unit] }
${ increment(sizeRef, sizeFun(tpe1.asMatchable, 'v.asTerm)).asExprOf[Unit] }
}.asTerm
)
val sizeRefExpr = sizeRef.asExprOf[Int]
Expand Down Expand Up @@ -354,7 +354,7 @@ trait BuildCodec extends Common:
).asExpr
else if p.tpe.isOption && p.tpe.optionArgument.asMatchable.isCommonType then
val tpe1 = p.tpe.optionArgument.asMatchable
val fun: Term = readFun(tpe1, is)
val fun: Term = readFun(tpe1.asMatchable, is)
Assign(
readRef
, Some_Apply(tpe=tpe1, value=fun)
Expand All @@ -371,7 +371,7 @@ trait BuildCodec extends Common:
)
else if p.tpe.isRepeated && p.tpe.repeatedArgument.asMatchable.isCommonType then
val tpe1 = p.tpe.repeatedArgument.asMatchable
val fun: Term = readFun(tpe1, is)
val fun: Term = readFun(tpe1.asMatchable, is)
val addOneApply = Select.unique(readRef, "addOne").appliedTo(fun).asExpr
if tpe1.isString || tpe1.isArrayByte || tpe1.isArraySeqByte || p.nonPacked then
addOneApply
Expand Down
32 changes: 16 additions & 16 deletions proto/src/main/scala-3/macrosapi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ private class Impl(using val qctx: Quotes) extends BuildCodec:
import report.*

def caseCodecAuto[A: Type]: Expr[MessageCodec[A]] =
val a_tpe = getCaseClassType[A].asMatchable
val a_tpe = getCaseClassType[A]
val aTypeSymbol = a_tpe.typeSymbol
val typeName = aTypeSymbol.fullName
val params: List[Symbol] = aTypeSymbol.constructorParams
Expand All @@ -55,24 +55,24 @@ private class Impl(using val qctx: Quotes) extends BuildCodec:
case Nil => errorAndAbort(s"missing ${NTpe.typeSymbol.name} annotation for `${typeName}`")
case _ => errorAndAbort(s"multiple ${NTpe.typeSymbol.name} annotations applied for `${typeName}`")
)
messageCodec(a_tpe, nums, params, restrictDefaults=true)
messageCodec(a_tpe.asMatchable, nums, params, restrictDefaults=true)

def caseCodecNums[A: Type](numsExpr: Expr[Seq[(String, Int)]])(using Quotes): Expr[MessageCodec[A]] =
val nums: Seq[(String, Int)] = numsExpr.valueOrAbort
val a_tpe = getCaseClassType[A].asMatchable
val a_tpe = getCaseClassType[A]
val aTypeSymbol = a_tpe.typeSymbol
val params: List[Symbol] = aTypeSymbol.constructorParams
messageCodec(a_tpe, nums, params, restrictDefaults=false)
messageCodec(a_tpe.asMatchable, nums, params, restrictDefaults=false)

def caseCodecIdx[A: Type]: Expr[MessageCodec[A]] =
val a_tpe = getCaseClassType[A].asMatchable
val a_tpe = getCaseClassType[A]
val aTypeSymbol = a_tpe.typeSymbol
val params: List[Symbol] = aTypeSymbol.constructorParams
val nums: List[(String, Int)] = params.zipWithIndex.map{case (p, idx) => (p.name, idx + 1) }
messageCodec(a_tpe, nums, params, restrictDefaults=false)
messageCodec(a_tpe.asMatchable, nums, params, restrictDefaults=false)

def classCodecAuto[A: Type]: Expr[MessageCodec[A]] =
val a_tpe = TypeRepr.of[A].asMatchable
val a_tpe = TypeRepr.of[A]
val aTypeSymbol = a_tpe.typeSymbol
val typeName = aTypeSymbol.fullName
val params: List[Symbol] = aTypeSymbol.constructorParams
Expand All @@ -87,15 +87,15 @@ private class Impl(using val qctx: Quotes) extends BuildCodec:
case Nil => errorAndAbort(s"missing ${NTpe.typeSymbol.name} annotation for `${typeName}`")
case _ => errorAndAbort(s"multiple ${NTpe.typeSymbol.name} annotations applied for `${typeName}`")
)
messageCodec(a_tpe, nums, params, restrictDefaults=true)
messageCodec(a_tpe.asMatchable, nums, params, restrictDefaults=true)

def classCodecNums[A: Type](
numsExpr: Expr[Seq[(String, Int)]]
)(
constructor: Expr[Any]
)(using Quotes): Expr[MessageCodec[A]] =
val nums: Seq[(String, Int)] = numsExpr.valueOrAbort
val a_tpe = TypeRepr.of[A].asMatchable
val a_tpe = TypeRepr.of[A]
val aTypeSymbol = a_tpe.typeSymbol
val typeName = aTypeSymbol.fullName
val members: List[Symbol] = aTypeSymbol.fieldMembers ++ aTypeSymbol.methodMembers
Expand All @@ -106,7 +106,7 @@ private class Impl(using val qctx: Quotes) extends BuildCodec:
case Some(s) => errorAndAbort(s"`${typeName}` field `${name}` is not a term")
case None => errorAndAbort(s"`${typeName}` has no field `${name}`")
}.toList
messageCodec(a_tpe, nums, params, restrictDefaults=false, constructor=Some(constructor.asTerm))
messageCodec(a_tpe.asMatchable, nums, params, restrictDefaults=false, constructor=Some(constructor.asTerm))

def messageCodec[A: Type](
a_tpe: TypeRepr & Matchable
Expand Down Expand Up @@ -196,18 +196,18 @@ private class Impl(using val qctx: Quotes) extends BuildCodec:
)

def enumByN[A: Type]: Expr[MessageCodec[A]] =
val a_tpe = TypeRepr.of[A].asMatchable
val a_tpe = TypeRepr.of[A]
val nums = collectNs(a_tpe)
sealedTraitCodec(a_tpe, nums)
sealedTraitCodec(a_tpe.asMatchable, nums)

def sealedTraitCodecAuto[A: Type]: Expr[MessageCodec[A]] =
val a_tpe = getSealedTrait[A].asMatchable
val a_tpe = getSealedTrait[A]
val nums = collectNs(a_tpe)
sealedTraitCodec(a_tpe, nums)
sealedTraitCodec(a_tpe.asMatchable, nums)

def sealedTraitCodecNums[A: Type](numsExpr: Expr[Seq[(String, Int)]]): Expr[MessageCodec[A]] =
val nums: Seq[(String, Int)] = numsExpr.valueOrAbort
val a_tpe = getSealedTrait[A].asMatchable
val a_tpe = getSealedTrait[A]
val nums1: List[(TypeRepr, Int)] =
a_tpe.asMatchable.knownFinalSubclasses.map{ x =>
x.tpe ->
Expand All @@ -217,7 +217,7 @@ private class Impl(using val qctx: Quotes) extends BuildCodec:
errorAndAbort(s"missing num for `${x.name}: ${x.fullName}`")
}
}
sealedTraitCodec(a_tpe, nums1)
sealedTraitCodec(a_tpe.asMatchable, nums1)

def sealedTraitCodec[A: Type](
a_tpe: TypeRepr & Matchable
Expand Down

0 comments on commit 4ab93f8

Please sign in to comment.