@@ -114,6 +114,9 @@ trait Deriving { this: Typer =>
114
114
sym
115
115
}
116
116
117
+ private def newMethod (name : TermName , info : Type , flags : FlagSet = EmptyFlags )(implicit ctx : Context ) =
118
+ ctx.newSymbol(ctx.owner, name, flags | Method | Synthetic , info, coord = cls.pos.startPos)
119
+
117
120
/** Enter type class instance with given name and info in current scope, provided
118
121
* an instance woth the same name does not exist already.
119
122
*/
@@ -124,7 +127,7 @@ trait Deriving { this: Typer =>
124
127
}
125
128
else {
126
129
val implFlag = if (reportErrors) Implicit else EmptyFlags // for now
127
- add(ctx.newSymbol(ctx.owner, instanceName, Synthetic | Method | implFlag, info, coord = cls.pos.startPos ))
130
+ add(newMethod( instanceName, info, implFlag ))
128
131
}
129
132
}
130
133
@@ -175,8 +178,29 @@ trait Deriving { this: Typer =>
175
178
addShape()
176
179
}
177
180
178
- def implementedClass (instance : Symbol ) =
179
- instance.info.stripPoly.finalResultType.classSymbol
181
+ private def shapedRHS (shapedType : Type , pos : Position )(implicit ctx : Context ) = {
182
+ import tpd ._
183
+ val AppliedType (_, clsArg :: shapeArg :: Nil ) = shapedType
184
+ val shape = shapeArg.dealias
185
+
186
+ val implClassSym = ctx.newNormalizedClassSymbol(
187
+ ctx.owner, tpnme.ANON_CLASS , EmptyFlags , shapedType :: Nil , coord = cls.pos.startPos)
188
+ val implClassCtx = ctx.withOwner(implClassSym)
189
+ val implClassConstr = newMethod(nme.CONSTRUCTOR , MethodType (Nil , implClassSym.typeRef))(implClassCtx).entered
190
+
191
+ def implClassStats (implicit ctx : Context ): List [Tree ] = {
192
+ val reflectMeth = newMethod(nme.reflect, MethodType (clsArg :: Nil , defn.MirrorType )).entered
193
+ val reifyMeth = newMethod(nme.reify, MethodType (defn.MirrorType :: Nil , clsArg)).entered
194
+ val commonMeth = newMethod(nme.common, ExprType (defn.ReflectedClassType )).entered
195
+ List (
196
+ tpd.DefDef (reflectMeth, tpd.ref(defn.Predef_undefinedR )), // TODO: flesh out
197
+ tpd.DefDef (reifyMeth, tpd.ref(defn.Predef_undefinedR )),
198
+ tpd.DefDef (commonMeth, tpd.ref(defn.Predef_undefinedR )))
199
+ }
200
+
201
+ val implClassDef = ClassDef (implClassSym, DefDef (implClassConstr), implClassStats(implClassCtx))
202
+ Block (implClassDef :: Nil , New (implClassSym.typeRef, Nil ))
203
+ }
180
204
181
205
private def typeclassInstance (sym : Symbol )(implicit ctx : Context ) =
182
206
(tparamRefs : List [Type ]) => (paramRefss : List [List [tpd.Tree ]]) => {
@@ -192,7 +216,7 @@ trait Deriving { this: Typer =>
192
216
val resultType = instantiated(sym.info)
193
217
val typeCls = resultType.classSymbol
194
218
if (typeCls == defn.ShapedClass )
195
- tpd.ref(defn. Predef_undefinedR ) // TODO: flesh out
219
+ shapedRHS(resultType, sym.pos)
196
220
else {
197
221
val module = untpd.ref(typeCls.companionModule.termRef).withPos(sym.pos)
198
222
val rhs = untpd.Select (module, nme.derived)
0 commit comments