File tree Expand file tree Collapse file tree 3 files changed +14
-4
lines changed
compiler/src/dotty/tools/dotc/transform Expand file tree Collapse file tree 3 files changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -147,6 +147,9 @@ class IsInstanceOfEvaluator extends MiniPhaseTransform { thisTransformer =>
147147 (scTrait && selTrait)
148148
149149 val inMatch = s.qualifier.symbol is Case
150+ // FIXME: This will misclassify case objects! We need to find another way to characterize
151+ // isInstanceOfs generated by matches.
152+ // Probably the most robust way is to use another symbol for the isInstanceOf method.
150153
151154 if (valueClassesOrAny) tree
152155 else if (knownStatically)
Original file line number Diff line number Diff line change @@ -104,8 +104,14 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisTran
104104 private def transformAnnot (annot : Annotation )(implicit ctx : Context ): Annotation =
105105 annot.derivedAnnotation(transformAnnot(annot.tree))
106106
107+ private def registerChild (sym : Symbol , tp : Type )(implicit ctx : Context ) = {
108+ val cls = tp.classSymbol
109+ if (cls.is(Sealed )) cls.addAnnotation(Annotation .makeChild(sym))
110+ }
111+
107112 private def transformMemberDef (tree : MemberDef )(implicit ctx : Context ): Unit = {
108113 val sym = tree.symbol
114+ if (sym.is(CaseVal , butNot = Module | Method )) registerChild(sym, sym.info)
109115 sym.transformAnnotations(transformAnnot)
110116 }
111117
@@ -227,10 +233,7 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisTran
227233
228234 // Add Child annotation to sealed parents unless current class is anonymous
229235 if (! sym.isAnonymousClass) // ignore anonymous class
230- for (parent <- sym.asClass.classInfo.classParents) {
231- val pclazz = parent.classSymbol
232- if (pclazz.is(Sealed )) pclazz.addAnnotation(Annotation .makeChild(sym))
233- }
236+ sym.asClass.classInfo.classParents.foreach(registerChild(sym, _))
234237
235238 tree
236239 }
Original file line number Diff line number Diff line change @@ -7,5 +7,9 @@ object Test {
77 for (color <- Color .enumValues) {
88 println(s " $color: ${color.enumTag}" )
99 assert(Color .enumValue(color.enumTag) eq color)
10+ import Color ._
11+ color match {
12+ case Red | Green | Blue =>
13+ }
1014 }
1115}
You can’t perform that action at this time.
0 commit comments