@@ -951,11 +951,19 @@ class Typer extends Namer
951
951
isContextual = funFlags.is(Given ), isErased = funFlags.is(Erased ))
952
952
953
953
/** Typechecks dependent function type with given parameters `params` */
954
- def typedDependent (params : List [ValDef ])(implicit ctx : Context ): Tree =
954
+ def typedDependent (params : List [untpd.ValDef ])(implicit ctx : Context ): Tree =
955
+ val fixThis = new untpd.UntypedTreeMap :
956
+ // pretype all references of this in outer context,
957
+ // so that they do not refer to the refined type being constructed
958
+ override def transform (tree : untpd.Tree )(using Context ): untpd.Tree = tree match
959
+ case This (id) => untpd.TypedSplice (typedExpr(tree)(using ctx.outer))
960
+ case _ => super .transform(tree)
961
+
955
962
val params1 =
956
963
if funFlags.is(Given ) then params.map(_.withAddedFlags(Given ))
957
964
else params
958
- val appDef0 = untpd.DefDef (nme.apply, Nil , List (params1), body, EmptyTree ).withSpan(tree.span)
965
+ val params2 = params1.map(fixThis.transformSub)
966
+ val appDef0 = untpd.DefDef (nme.apply, Nil , List (params2), body, EmptyTree ).withSpan(tree.span)
959
967
index(appDef0 :: Nil )
960
968
val appDef = typed(appDef0).asInstanceOf [DefDef ]
961
969
val mt = appDef.symbol.info.asInstanceOf [MethodType ]
@@ -966,10 +974,11 @@ class Typer extends Namer
966
974
val tycon = TypeTree (funCls.typeRef)
967
975
val core = AppliedTypeTree (tycon, typeArgs)
968
976
RefinedTypeTree (core, List (appDef), ctx.owner.asClass)
977
+ end typedDependent
969
978
970
979
args match {
971
980
case ValDef (_, _, _) :: _ =>
972
- typedDependent(args.asInstanceOf [List [ValDef ]])(
981
+ typedDependent(args.asInstanceOf [List [untpd. ValDef ]])(
973
982
ctx.fresh.setOwner(ctx.newRefinedClassSymbol(tree.span)).setNewScope)
974
983
case _ =>
975
984
typed(cpy.AppliedTypeTree (tree)(untpd.TypeTree (funCls.typeRef), args :+ body), pt)
0 commit comments