Skip to content

Commit 02435f1

Browse files
committed
Ensure ExprType treat underlying annotations correctly
ExprTypes sometimes hold `AnnotatedType` underneath. Make sure they are handled: - Before transformation, check under ExprTypes in `hasAnnotation` - During transformation, change `=> @annot T` to `@annot () ?=> T` instead of `() ?=> @annot T` This makes `erased => T` parameters work, although it is of little value...
1 parent 78d2d67 commit 02435f1

File tree

2 files changed

+3
-0
lines changed

2 files changed

+3
-0
lines changed

compiler/src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,6 +1179,8 @@ class Definitions {
11791179
def apply(tp: Type)(using Context): Type = tp match
11801180
case tp @ EventuallyCapturingType(tp1, refs) if tp.annot.symbol == RetainsByNameAnnot =>
11811181
CapturingType(apply(tp1), refs)
1182+
case AnnotatedType(parent, annot) =>
1183+
AnnotatedType(apply(parent), annot)
11821184
case _ =>
11831185
defn.ContextFunction0.typeRef.appliedTo(tp :: Nil)
11841186
def unapply(tp: Type)(using Context): Option[Type] = tp match

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,7 @@ object Types {
374374
/** Does the type carry an annotation that is an instance of `cls`? */
375375
@tailrec final def hasAnnotation(cls: ClassSymbol)(using Context): Boolean = stripTypeVar match {
376376
case AnnotatedType(tp, annot) => (annot matches cls) || (tp hasAnnotation cls)
377+
case ExprType(tp) => tp.hasAnnotation(cls) // ExprType closes over the underlying annotated type. See `addAnnotation`.
377378
case _ => false
378379
}
379380

0 commit comments

Comments
 (0)