@@ -15,14 +15,14 @@ trait ImplicitOps extends Base {
15
15
}
16
16
17
17
trait 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 ]
19
19
20
20
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 )
22
22
}
23
23
24
24
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)
26
26
case _ => super .mirror(e,f)
27
27
}).asInstanceOf [Exp [A ]]
28
28
@@ -33,9 +33,9 @@ trait ScalaGenImplicitOps extends ScalaGenBase {
33
33
import IR ._
34
34
35
35
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))
39
39
case _ => super .emitNode(sym, rhs)
40
40
}
41
41
}
@@ -46,8 +46,8 @@ trait CLikeGenImplicitOps extends CLikeGenBase {
46
46
47
47
override def emitNode (sym : Sym [Any ], rhs : Def [Any ]) = {
48
48
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; "
51
51
case _ => super .emitNode(sym, rhs)
52
52
}
53
53
}
0 commit comments