Skip to content

Commit e09bb5d

Browse files
committed
Replace annotation extractor with access methods
1 parent 68e90c4 commit e09bb5d

File tree

5 files changed

+38
-38
lines changed

5 files changed

+38
-38
lines changed

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

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -185,23 +185,6 @@ object Annotations {
185185
else None
186186
}
187187

188-
/** Extractor for opaque alias annotations */
189-
object OpaqueAlias {
190-
def apply(tp: Type, companion: Symbol)(implicit ctx: Context): Annotation = {
191-
val arg = if (companion.exists) RefinedType(tp, nme.companion, companion.termRef) else tp
192-
Annotation(TypeTree(defn.OpaqueAliasAnnot.typeRef.appliedTo(arg)))
193-
}
194-
def unapply(ann: Annotation)(implicit ctx: Context): Option[(Type, Symbol)] =
195-
if (ann.symbol == defn.OpaqueAliasAnnot) {
196-
ann.tree.tpe match {
197-
case AppliedType(_, RefinedType(tp, nme.companion, ref) :: Nil) => Some((tp, ref.termSymbol))
198-
case AppliedType(_, tp :: Nil) => Some((tp, NoSymbol))
199-
case _ => None
200-
}
201-
}
202-
else None
203-
}
204-
205188
/** Extractor for linked type annotations */
206189
object LinkedType extends TypeHintExtractor(implicit ctx => defn.LinkedTypeAnnot)
207190

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ object StdNames {
246246

247247
// Compiler-internal
248248
val ANYname: N = "<anyname>"
249+
val COMPANION: N = "<companion>"
249250
val CONSTRUCTOR: N = "<init>"
250251
val STATIC_CONSTRUCTOR: N = "<clinit>"
251252
val DEFAULT_CASE: N = "defaultCase$"
@@ -394,7 +395,6 @@ object StdNames {
394395
val classOf: N = "classOf"
395396
val clone_ : N = "clone"
396397
// val conforms : N = "conforms" // Dotty deviation: no special treatment of conforms, so the occurrence of the name here would cause to unintended implicit shadowing. Should find a less common name for it in Predef.
397-
val companion: N = "companion"
398398
val copy: N = "copy"
399399
val currentMirror: N = "currentMirror"
400400
val create: N = "create"

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

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -390,9 +390,12 @@ object SymDenotations {
390390
}
391391
if (is(Opaque)) {
392392
info match {
393-
case tp @ TypeAlias(alias) =>
393+
case TypeAlias(alias) =>
394394
val companion = companionNamed(name.moduleClassName).sourceModule
395-
addAnnotation(Annotation.OpaqueAlias(alias, companion))
395+
val arg =
396+
if (companion.exists) RefinedType(alias, nme.COMPANION, companion.termRef)
397+
else alias
398+
addAnnotation(Annotation(tpd.TypeTree(defn.OpaqueAliasAnnot.typeRef.appliedTo(arg))))
396399
info = TypeBounds(defn.NothingType, abstractRHS(alias))
397400
setFlag(Deferred)
398401
case _ =>
@@ -971,8 +974,13 @@ object SymDenotations {
971974
if (is(Module)) sourceModule
972975
else if (is(Opaque))
973976
getAnnotation(defn.OpaqueAliasAnnot) match {
974-
case Some(Annotation.OpaqueAlias(_, ref)) => ref
975-
case _ => NoSymbol
977+
case Some(ann) =>
978+
val AppliedType(_, arg :: Nil) = ann.tree.tpe
979+
arg match {
980+
case RefinedType(tp, _, ref) => ref.termSymbol
981+
case _ => NoSymbol
982+
}
983+
case None => NoSymbol
976984
}
977985
else
978986
getAnnotation(defn.LinkedTypeAnnot) match {
@@ -1052,6 +1060,21 @@ object SymDenotations {
10521060
final def enclosingSubClass(implicit ctx: Context) =
10531061
ctx.owner.ownersIterator.findSymbol(_.isSubClass(symbol))
10541062

1063+
/** The alias of an opaque type */
1064+
def opaqueAlias(implicit ctx: Context): Type = {
1065+
if (is(Opaque))
1066+
getAnnotation(defn.OpaqueAliasAnnot) match {
1067+
case Some(ann) =>
1068+
val AppliedType(_, arg :: Nil) = ann.tree.tpe
1069+
arg match {
1070+
case RefinedType(tp, nme.COMPANION, _) => tp
1071+
case tp => tp
1072+
}
1073+
case None => NoType
1074+
}
1075+
else NoType
1076+
}
1077+
10551078
/** The non-private symbol whose name and type matches the type of this symbol
10561079
* in the given class.
10571080
* @param inClass The class containing the result symbol's definition

compiler/src/dotty/tools/dotc/transform/FirstTransform.scala

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,12 @@ class FirstTransform extends MiniPhase with SymTransformer { thisPhase =>
6464
sym.copySymDenotation(info = tp.derivedClassInfo(selfInfo = self.info))
6565
.copyCaches(sym, ctx.phase.next)
6666
case _ =>
67-
if (sym.is(Opaque))
68-
sym.getAnnotation(defn.OpaqueAliasAnnot) match {
69-
case Some(Annotation.OpaqueAlias(rhs, _)) =>
70-
val result = sym.copySymDenotation(info = TypeAlias(rhs))
71-
result.removeAnnotation(defn.OpaqueAliasAnnot)
72-
result.resetFlag(Opaque)
73-
result.resetFlag(Deferred)
74-
result
75-
case _ =>
76-
sym
77-
}
67+
if (sym.is(Opaque)) {
68+
val result = sym.copySymDenotation(info = TypeAlias(sym.opaqueAlias))
69+
result.removeAnnotation(defn.OpaqueAliasAnnot)
70+
result.resetFlag(Opaque | Deferred)
71+
result
72+
}
7873
else sym
7974
}
8075

compiler/src/dotty/tools/dotc/typer/Namer.scala

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,10 @@ trait NamerContextOps { this: Context =>
110110
}
111111
if (ctx.owner.is(Module)) {
112112
val opaq = ctx.owner.companionOpaqueType
113-
opaq.getAnnotation(defn.OpaqueAliasAnnot) match {
114-
case Some(Annotation.OpaqueAlias(rhs, _)) =>
115-
localCtx = localCtx.setFreshGADTBounds
116-
localCtx.gadt.setBounds(opaq, TypeAlias(rhs))
117-
case _ =>
113+
val alias = opaq.opaqueAlias
114+
if (alias.exists) {
115+
localCtx = localCtx.setFreshGADTBounds
116+
localCtx.gadt.setBounds(opaq, TypeAlias(alias))
118117
}
119118
}
120119
localCtx

0 commit comments

Comments
 (0)