File tree 3 files changed +14
-4
lines changed
compiler/src/dotty/tools/dotc/transform
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 =>
147
147
(scTrait && selTrait)
148
148
149
149
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.
150
153
151
154
if (valueClassesOrAny) tree
152
155
else if (knownStatically)
Original file line number Diff line number Diff line change @@ -104,8 +104,14 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisTran
104
104
private def transformAnnot (annot : Annotation )(implicit ctx : Context ): Annotation =
105
105
annot.derivedAnnotation(transformAnnot(annot.tree))
106
106
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
+
107
112
private def transformMemberDef (tree : MemberDef )(implicit ctx : Context ): Unit = {
108
113
val sym = tree.symbol
114
+ if (sym.is(CaseVal , butNot = Module | Method )) registerChild(sym, sym.info)
109
115
sym.transformAnnotations(transformAnnot)
110
116
}
111
117
@@ -227,10 +233,7 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisTran
227
233
228
234
// Add Child annotation to sealed parents unless current class is anonymous
229
235
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, _))
234
237
235
238
tree
236
239
}
Original file line number Diff line number Diff line change @@ -7,5 +7,9 @@ object Test {
7
7
for (color <- Color .enumValues) {
8
8
println(s " $color: ${color.enumTag}" )
9
9
assert(Color .enumValue(color.enumTag) eq color)
10
+ import Color ._
11
+ color match {
12
+ case Red | Green | Blue =>
13
+ }
10
14
}
11
15
}
You can’t perform that action at this time.
0 commit comments