From c715444479c07d5b1661b4bec924cc5401f1ea78 Mon Sep 17 00:00:00 2001 From: Matt Bovel Date: Thu, 13 Apr 2023 21:24:45 +0200 Subject: [PATCH 1/2] Enable temporary paramInfos while executing paramInfosExp --- .../src/dotty/tools/dotc/core/Types.scala | 19 +++++++++++++------ tests/pos/termDependentAnnotation.scala | 3 +++ 2 files changed, 16 insertions(+), 6 deletions(-) create mode 100644 tests/pos/termDependentAnnotation.scala diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala index fe0fc8a6dc2d..cf08a7aafcd3 100644 --- a/compiler/src/dotty/tools/dotc/core/Types.scala +++ b/compiler/src/dotty/tools/dotc/core/Types.scala @@ -3925,12 +3925,15 @@ object Types { abstract case class MethodType(paramNames: List[TermName])( paramInfosExp: MethodType => List[Type], - resultTypeExp: MethodType => Type) + resultTypeExp: MethodType => Type, + tempParamInfos: List[Type] | Null = null) extends MethodOrPoly with TermLambda with NarrowCached { thisMethodType => type This = MethodType - val paramInfos: List[Type] = paramInfosExp(this: @unchecked) + val _paramInfos: List[Type] | Null = paramInfosExp(this: @unchecked) + def paramInfos = if _paramInfos != null then _paramInfos else tempParamInfos + val resType: Type = resultTypeExp(this: @unchecked) assert(resType.exists) @@ -3949,8 +3952,8 @@ object Types { protected def prefixString: String = companion.prefixString } - final class CachedMethodType(paramNames: List[TermName])(paramInfosExp: MethodType => List[Type], resultTypeExp: MethodType => Type, val companion: MethodTypeCompanion) - extends MethodType(paramNames)(paramInfosExp, resultTypeExp) + final class CachedMethodType(paramNames: List[TermName])(paramInfosExp: MethodType => List[Type], resultTypeExp: MethodType => Type, val companion: MethodTypeCompanion, tempParamInfos: List[Type] | Null = null) + extends MethodType(paramNames)(paramInfosExp, resultTypeExp, tempParamInfos) abstract class LambdaTypeCompanion[N <: Name, PInfo <: Type, LT <: LambdaType] { def syntheticParamName(n: Int): N @@ -4038,11 +4041,15 @@ object Types { apply(params.map(_.name.asTermName))( tl => params.map(p => tl.integrate(params, paramInfo(p))), - tl => tl.integrate(params, resultType)) + tl => tl.integrate(params, resultType), + params.map(paramInfo)) end fromSymbols def apply(paramNames: List[TermName])(paramInfosExp: MethodType => List[Type], resultTypeExp: MethodType => Type)(using Context): MethodType = - checkValid(unique(new CachedMethodType(paramNames)(paramInfosExp, resultTypeExp, self))) + apply(paramNames)(paramInfosExp, resultTypeExp, null) + + def apply(paramNames: List[TermName])(paramInfosExp: MethodType => List[Type], resultTypeExp: MethodType => Type, tempParamInfos: List[Type] | Null = null)(using Context): MethodType = + checkValid(unique(new CachedMethodType(paramNames)(paramInfosExp, resultTypeExp, self, tempParamInfos))) def checkValid(mt: MethodType)(using Context): mt.type = { if (Config.checkMethodTypes) diff --git a/tests/pos/termDependentAnnotation.scala b/tests/pos/termDependentAnnotation.scala new file mode 100644 index 000000000000..349e4518b8b7 --- /dev/null +++ b/tests/pos/termDependentAnnotation.scala @@ -0,0 +1,3 @@ + +class local(predicate: Boolean) extends annotation.StaticAnnotation +def f(x: Int, z: Int @local(x == x)) = ??? From f921e92f5570c44d20109f70f0da2d20fbd6fd56 Mon Sep 17 00:00:00 2001 From: Matt Bovel Date: Thu, 13 Apr 2023 21:54:14 +0200 Subject: [PATCH 2/2] Restore non-null paramInfos return type --- compiler/src/dotty/tools/dotc/core/Types.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala index cf08a7aafcd3..4f62b2d84a2a 100644 --- a/compiler/src/dotty/tools/dotc/core/Types.scala +++ b/compiler/src/dotty/tools/dotc/core/Types.scala @@ -3932,7 +3932,7 @@ object Types { type This = MethodType val _paramInfos: List[Type] | Null = paramInfosExp(this: @unchecked) - def paramInfos = if _paramInfos != null then _paramInfos else tempParamInfos + override def paramInfos: List[Type] = if _paramInfos != null then _paramInfos else tempParamInfos.uncheckedNN val resType: Type = resultTypeExp(this: @unchecked) assert(resType.exists)