From 52db67803504eba03dd9c51d78579ce9c9796037 Mon Sep 17 00:00:00 2001 From: Matt Bovel Date: Thu, 27 Nov 2025 10:37:59 +0000 Subject: [PATCH 1/2] Strip CC annotations in TypeMap when CC is not enabled --- compiler/src/dotty/tools/dotc/core/Types.scala | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala index 5d630cad6368..f41873aad9cc 100644 --- a/compiler/src/dotty/tools/dotc/core/Types.scala +++ b/compiler/src/dotty/tools/dotc/core/Types.scala @@ -30,6 +30,7 @@ import Hashable.* import Uniques.* import collection.mutable import config.Config +import config.Feature import config.Feature.sourceVersion import config.SourceVersion import annotation.{tailrec, constructorOnly} @@ -6483,10 +6484,13 @@ object Types extends TypeUtils { mapCapturingType(tp, parent, refs, variance) case tp @ AnnotatedType(underlying, annot) => - val underlying1 = this(underlying) - val annot1 = annot.mapWith(this) - if annot1 eq EmptyAnnotation then underlying1 - else derivedAnnotatedType(tp, underlying1, annot1) + if annot.symbol.isRetainsLike && !Feature.ccEnabledSomewhere then + this(underlying) // strip retains like annotations unless capture checking is enabled + else + val underlying1 = this(underlying) + val annot1 = annot.mapWith(this) + if annot1 eq EmptyAnnotation then underlying1 + else derivedAnnotatedType(tp, underlying1, annot1) case _: ThisType | _: BoundType From fe1dfeea797e7e814eb6e2d06662a74f1d932802 Mon Sep 17 00:00:00 2001 From: Matt Bovel Date: Thu, 27 Nov 2025 14:30:50 +0000 Subject: [PATCH 2/2] Keep opaque types in FollowAliasesMap --- compiler/src/dotty/tools/dotc/core/Types.scala | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala index f41873aad9cc..86223cde31c9 100644 --- a/compiler/src/dotty/tools/dotc/core/Types.scala +++ b/compiler/src/dotty/tools/dotc/core/Types.scala @@ -6280,12 +6280,12 @@ object Types extends TypeUtils { end BiTypeMap - /** A typemap that follows aliases and keeps their transformed results if - * there is a change. - */ + /** A typemap that follows non-opaque aliases and keeps their transformed + * results if there is a change. + */ trait FollowAliasesMap(using Context) extends TypeMap: def mapFollowingAliases(t: Type): Type = - val t1 = t.dealiasKeepAnnots + val t1 = t.dealiasKeepAnnotsAndOpaques if t1 ne t then val t2 = apply(t1) if t2 ne t1 then t2