@@ -932,11 +932,19 @@ class Typer extends Namer
932
932
isContextual = funFlags.is(Given ), isErased = funFlags.is(Erased ))
933
933
934
934
/** Typechecks dependent function type with given parameters `params` */
935
- def typedDependent (params : List [ValDef ])(implicit ctx : Context ): Tree =
935
+ def typedDependent (params : List [untpd.ValDef ])(implicit ctx : Context ): Tree =
936
+ val fixThis = new untpd.UntypedTreeMap :
937
+ // pretype all references of this in outer context,
938
+ // so that they do not refer to the refined type being constructed
939
+ override def transform (tree : untpd.Tree )(using Context ): untpd.Tree = tree match
940
+ case This (id) => untpd.TypedSplice (typedExpr(tree)(using ctx.outer))
941
+ case _ => super .transform(tree)
942
+
936
943
val params1 =
937
944
if funFlags.is(Given ) then params.map(_.withAddedFlags(Given ))
938
945
else params
939
- val appDef0 = untpd.DefDef (nme.apply, Nil , List (params1), body, EmptyTree ).withSpan(tree.span)
946
+ val params2 = params1.map(fixThis.transformSub)
947
+ val appDef0 = untpd.DefDef (nme.apply, Nil , List (params2), body, EmptyTree ).withSpan(tree.span)
940
948
index(appDef0 :: Nil )
941
949
val appDef = typed(appDef0).asInstanceOf [DefDef ]
942
950
val mt = appDef.symbol.info.asInstanceOf [MethodType ]
@@ -947,10 +955,11 @@ class Typer extends Namer
947
955
val tycon = TypeTree (funCls.typeRef)
948
956
val core = AppliedTypeTree (tycon, typeArgs)
949
957
RefinedTypeTree (core, List (appDef), ctx.owner.asClass)
958
+ end typedDependent
950
959
951
960
args match {
952
961
case ValDef (_, _, _) :: _ =>
953
- typedDependent(args.asInstanceOf [List [ValDef ]])(
962
+ typedDependent(args.asInstanceOf [List [untpd. ValDef ]])(
954
963
ctx.fresh.setOwner(ctx.newRefinedClassSymbol(tree.span)).setNewScope)
955
964
case _ =>
956
965
typed(cpy.AppliedTypeTree (tree)(untpd.TypeTree (funCls.typeRef), args :+ body), pt)
0 commit comments