@@ -21,7 +21,7 @@ import annotation.constructorOnly
21
21
import ast .tpd
22
22
import printing .{Printer , Showable }
23
23
import printing .Texts .Text
24
- import reporting .Message
24
+ import reporting .{ Message , trace }
25
25
import NameOps .isImpureFunction
26
26
import annotation .internal .sharable
27
27
@@ -693,7 +693,7 @@ object Capabilities:
693
693
thisMap =>
694
694
695
695
override def apply (t : Type ) =
696
- if variance <= 0 then t
696
+ if variance < 0 then t
697
697
else t match
698
698
case t @ CapturingType (_, _) =>
699
699
mapOver(t)
@@ -703,6 +703,8 @@ object Capabilities:
703
703
this (CapturingType (parent1, ann.tree.toCaptureSet))
704
704
else
705
705
t.derivedAnnotatedType(parent1, ann)
706
+ case defn.RefinedFunctionOf (_) =>
707
+ t // stop at dependent function types
706
708
case _ =>
707
709
mapFollowingAliases(t)
708
710
@@ -784,7 +786,7 @@ object Capabilities:
784
786
abstract class CapMap extends BiTypeMap :
785
787
override def mapOver (t : Type ): Type = t match
786
788
case t @ FunctionOrMethod (args, res) if variance > 0 && ! t.isAliasFun =>
787
- t // `t` should be mapped in this case by a different call to `mapCap` .
789
+ t // `t` should be mapped in this case by a different call to `toResult`. See [[toResultInResults]] .
788
790
case t : (LazyRef | TypeVar ) =>
789
791
mapConserveSuper(t)
790
792
case _ =>
@@ -849,7 +851,8 @@ object Capabilities:
849
851
end toResult
850
852
851
853
/** Map global roots in function results to result roots. Also,
852
- * map roots in the types of parameterless def methods.
854
+ * map roots in the types of def methods that are parameterless
855
+ * or have only type parameters.
853
856
*/
854
857
def toResultInResults (sym : Symbol , fail : Message => Unit , keepAliases : Boolean = false )(tp : Type )(using Context ): Type =
855
858
val m = new TypeMap with FollowAliasesMap :
@@ -878,8 +881,19 @@ object Capabilities:
878
881
throw ex
879
882
m(tp) match
880
883
case tp1 : ExprType if sym.is(Method , butNot = Accessor ) =>
884
+ // Map the result of parameterless `def` methods.
881
885
tp1.derivedExprType(toResult(tp1.resType, tp1, fail))
886
+ case tp1 : PolyType if ! tp1.resType.isInstanceOf [MethodicType ] =>
887
+ // Map also the result type of method with only type parameters.
888
+ // This way, the `^` in the following method will be mapped to a `ResultCap`:
889
+ // ```
890
+ // object Buffer:
891
+ // def empty[T]: Buffer[T]^
892
+ // ```
893
+ // This is more desirable than interpreting `^` as a `Fresh` at the level of `Buffer.empty`
894
+ // in most cases.
895
+ tp1.derivedLambdaType(resType = toResult(tp1.resType, tp1, fail))
882
896
case tp1 => tp1
883
897
end toResultInResults
884
898
885
- end Capabilities
899
+ end Capabilities
0 commit comments