-
Notifications
You must be signed in to change notification settings - Fork 1.1k
[Deprecated] exhaustivity & redundancy check for pattern matching #1261
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
5cdd42f
9a0952c
fd1b286
d681a78
da9511d
89e8ff9
b25e952
e2db834
2d6e803
f69b305
c79181d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,8 @@ import Symbols._, TypeUtils._ | |
* | ||
* (9) Adds SourceFile annotations to all top-level classes and objects | ||
* | ||
* (10) Adds Child annotations to all sealed classes | ||
* | ||
* The reason for making this a macro transform is that some functions (in particular | ||
* super and protected accessors and instantiation checks) are naturally top-down and | ||
* don't lend themselves to the bottom-up approach of a mini phase. The other two functions | ||
|
@@ -231,6 +233,13 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisTran | |
ctx.compilationUnit.source.exists && | ||
sym != defn.SourceFileAnnot) | ||
sym.addAnnotation(Annotation.makeSourceFile(ctx.compilationUnit.source.file.path)) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we're unlucky, this will conflict with #1343. |
||
if (!sym.isAnonymousClass) // ignore anonymous class | ||
for (parent <- sym.asClass.classInfo.classParents) { | ||
val pclazz = parent.classSymbol | ||
if (pclazz.is(Sealed)) pclazz.addAnnotation(Annotation.makeChild(sym)) | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Anonymous classes caused pickling-related error for https://gist.github.com/liufengyun/f4aca0853e06f96c9130a0a05bfa0d4f If I ignore anonymous classes, then it works: if (!sym.isAnonymousClass) // ignore anonymous class
for (parent <- sym.asClass.classInfo.classParents) {
val pclazz = parent.classSymbol
if (pclazz.is(Sealed)) pclazz.addAnnotation(Annotation.makeChild(sym))
} The problem is that ignore anonymous classes would make the algorithm silent in case it should report a warning: sealed trait A
case class B() extends A
case class C() extends A
object M {
val x = new A {}
x match {
case _: B => true
case _: C => true
}
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If a sealed trait has direct anonymous subclasses then it's impossible to pattern match on all subclasses. I think the simplest solution is to disallow direct anonymous subclasses of sealed traits. |
||
tree | ||
} | ||
else { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PatternMatcher now has a 🌠SpaceEngine🌠 and can do interstellar travels. Looking forward to battle space invaders.
👾👾👾👾