diff options
author | Paul Phillips <paulp@improving.org> | 2012-08-10 07:28:56 -0700 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2012-08-10 12:30:54 -0700 |
commit | 0aa77ffa7cf2a95d9d84d4bc5e635163a84ca931 (patch) | |
tree | 831815116e90f6d87dd42b3d379449c1db2aad80 /src/reflect/scala/reflect/internal/TreeInfo.scala | |
parent | fbbbb2294680c0f57506f885971b148cae53c92d (diff) | |
download | scala-0aa77ffa7cf2a95d9d84d4bc5e635163a84ca931.tar.gz scala-0aa77ffa7cf2a95d9d84d4bc5e635163a84ca931.tar.bz2 scala-0aa77ffa7cf2a95d9d84d4bc5e635163a84ca931.zip |
Warn about catching non-local returns.
Almost every time someone is shooting themself in the foot
by catching a non-local return, it is apparent from the
structure of the AST that they are doing so. Warn them.
Diffstat (limited to 'src/reflect/scala/reflect/internal/TreeInfo.scala')
-rw-r--r-- | src/reflect/scala/reflect/internal/TreeInfo.scala | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/reflect/scala/reflect/internal/TreeInfo.scala b/src/reflect/scala/reflect/internal/TreeInfo.scala index 1b4c1b2877..e92cfba1c5 100644 --- a/src/reflect/scala/reflect/internal/TreeInfo.scala +++ b/src/reflect/scala/reflect/internal/TreeInfo.scala @@ -402,11 +402,15 @@ abstract class TreeInfo { def catchesThrowable(cdef: CaseDef) = catchesAllOf(cdef, ThrowableClass.tpe) /** Does this CaseDef catch everything of a certain Type? */ - def catchesAllOf(cdef: CaseDef, threshold: Type) = - isDefaultCase(cdef) || (cdef.guard.isEmpty && (unbind(cdef.pat) match { - case Typed(Ident(nme.WILDCARD), tpt) => (tpt.tpe != null) && (threshold <:< tpt.tpe) - case _ => false - })) + def catchesAllOf(cdef: CaseDef, threshold: Type) = { + def unbound(t: Tree) = t.symbol == null || t.symbol == NoSymbol + cdef.guard.isEmpty && (unbind(cdef.pat) match { + case Ident(nme.WILDCARD) => true + case i@Ident(name) => unbound(i) + case Typed(_, tpt) => (tpt.tpe != null) && (threshold <:< tpt.tpe) + case _ => false + }) + } /** Is this pattern node a catch-all or type-test pattern? */ def isCatchCase(cdef: CaseDef) = cdef match { |