@@ -15,14 +15,14 @@ trait ImplicitOps extends Base {
1515}
1616
1717trait ImplicitOpsExp extends ImplicitOps with BaseExp {
18- case class ImplicitConvert [X ,Y ](x : Exp [X ])( implicit val mX : Manifest [X ], val mY : Manifest [Y ]) extends Def [Y ]
18+ case class ImplicitConvert [X ,Y ](x : Exp [X ], mY : Manifest [Y ])( implicit val mX : Manifest [X ]) extends Def [Y ]
1919
2020 def implicit_convert [X ,Y ](x : Exp [X ])(implicit c : X => Y , mX : Manifest [X ], mY : Manifest [Y ], pos : SourceContext ) : Rep [Y ] = {
21- if (mX == mY) x.asInstanceOf [Rep [Y ]] else ImplicitConvert [X ,Y ](x)
21+ if (mX == mY) x.asInstanceOf [Rep [Y ]] else ImplicitConvert [X ,Y ](x, mY )
2222 }
2323
2424 override def mirror [A : Manifest ](e : Def [A ], f : Transformer )(implicit pos : SourceContext ): Exp [A ] = (e match {
25- case im@ ImplicitConvert (x) => toAtom(ImplicitConvert (f(x))(im.mX,im.mY ))(mtype(manifest[A ]),pos)
25+ case im@ ImplicitConvert (x, mY ) => toAtom(ImplicitConvert (f(x), mY )(im.mX))(mtype(manifest[A ]),pos)
2626 case _ => super .mirror(e,f)
2727 }).asInstanceOf [Exp [A ]]
2828
@@ -33,9 +33,9 @@ trait ScalaGenImplicitOps extends ScalaGenBase {
3333 import IR ._
3434
3535 override def emitNode (sym : Sym [Any ], rhs : Def [Any ]) = rhs match {
36- // TODO: this valDef is redundant; we really just want the conversion to be a no-op in the generated code.
37- // TODO: but we still need to link the defs together
38- case ImplicitConvert (x) => emitValDef (sym, quote(x))
36+ // Make sure it's typed to trigger the implicit conversion
37+ // Otherwise we can get type mismatch in generated code
38+ case ImplicitConvert (x, mY ) => emitTypedValDef (sym, quote(x))
3939 case _ => super .emitNode(sym, rhs)
4040 }
4141}
@@ -46,8 +46,8 @@ trait CLikeGenImplicitOps extends CLikeGenBase {
4646
4747 override def emitNode (sym : Sym [Any ], rhs : Def [Any ]) = {
4848 rhs match {
49- case im @ ImplicitConvert (x) =>
50- gen " ${im.mY} $sym = ( ${im.mY} ) $x; "
49+ case ImplicitConvert (x, mY ) =>
50+ gen " $mY $sym = ( $mY ) $x; "
5151 case _ => super .emitNode(sym, rhs)
5252 }
5353 }
0 commit comments