diff options
Diffstat (limited to 'src/compiler')
5 files changed, 44 insertions, 20 deletions
diff --git a/src/compiler/scala/tools/nsc/backend/jvm/GenJVMASM.scala b/src/compiler/scala/tools/nsc/backend/jvm/GenJVMASM.scala index f0f91e7d1a..50fd59b23f 100644 --- a/src/compiler/scala/tools/nsc/backend/jvm/GenJVMASM.scala +++ b/src/compiler/scala/tools/nsc/backend/jvm/GenJVMASM.scala @@ -78,17 +78,19 @@ trait GenJVMASM { failNoForwarder("companion is a trait") // Now either succeeed, or issue some additional warnings for things which look like // attempts to be java main methods. - else possibles exists { m => - m.info match { - case PolyType(_, _) => - fail("main methods cannot be generic.") - case MethodType(params, res) => - if (res.typeSymbol :: params exists (_.isAbstractType)) - fail("main methods cannot refer to type parameters or abstract types.", m.pos) - else - isJavaMainMethod(m) || fail("main method must have exact signature (Array[String])Unit", m.pos) - case tp => - fail("don't know what this is: " + tp, m.pos) + else (possibles exists isJavaMainMethod) || { + possibles exists { m => + m.info match { + case PolyType(_, _) => + fail("main methods cannot be generic.") + case MethodType(params, res) => + if (res.typeSymbol :: params exists (_.isAbstractType)) + fail("main methods cannot refer to type parameters or abstract types.", m.pos) + else + isJavaMainMethod(m) || fail("main method must have exact signature (Array[String])Unit", m.pos) + case tp => + fail("don't know what this is: " + tp, m.pos) + } } } } diff --git a/src/compiler/scala/tools/nsc/interpreter/TypeStrings.scala b/src/compiler/scala/tools/nsc/interpreter/TypeStrings.scala index 239dbb8149..33311f5bb3 100644 --- a/src/compiler/scala/tools/nsc/interpreter/TypeStrings.scala +++ b/src/compiler/scala/tools/nsc/interpreter/TypeStrings.scala @@ -205,7 +205,7 @@ trait TypeStrings { } private def tparamString[T: ru.TypeTag] : String = { - import ru._ + import ru._ // get TypeRefTag in scope so that pattern match works (TypeRef is an abstract type) def typeArguments: List[ru.Type] = ru.typeOf[T] match { case ru.TypeRef(_, _, args) => args; case _ => Nil } brackets(typeArguments map (jc => tvarString(List(jc))): _*) } diff --git a/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala b/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala index 07135c3af9..ff3e856471 100644 --- a/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala +++ b/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala @@ -146,11 +146,23 @@ trait SyntheticMethods extends ast.TreeDSL { Ident(m.firstParam) IS_OBJ classExistentialType(clazz)) } - /** (that.isInstanceOf[this.C]) - * where that is the given methods first parameter. + /** that match { case _: this.C => true ; case _ => false } + * where `that` is the given method's first parameter. + * + * An isInstanceOf test is insufficient because it has weaker + * requirements than a pattern match. Given an inner class Foo and + * two different instantiations of the container, an x.Foo and and a y.Foo + * are both .isInstanceOf[Foo], but the one does not match as the other. */ - def thatTest(eqmeth: Symbol): Tree = - gen.mkIsInstanceOf(Ident(eqmeth.firstParam), classExistentialType(clazz), true, false) + def thatTest(eqmeth: Symbol): Tree = { + Match( + Ident(eqmeth.firstParam), + List( + CaseDef(Typed(Ident(nme.WILDCARD), TypeTree(clazz.tpe)), EmptyTree, TRUE), + CaseDef(WILD.empty, EmptyTree, FALSE) + ) + ) + } /** (that.asInstanceOf[this.C]) * where that is the given methods first parameter. diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index d72978cb1a..b853f687a7 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -5189,12 +5189,18 @@ trait Typers extends Modes with Adaptations with Tags { "context.owner" -> context.owner ) ) - val tree1 = typed1(tree, mode, dropExistential(pt)) + typed1(tree, mode, dropExistential(pt)) + } + // Can happen during erroneous compilation - error(s) have been + // reported, but we need to avoid causing an NPE with this tree + if (tree1.tpe eq null) + return setError(tree) + + if (!alreadyTyped) { printTyping("typed %s: %s%s".format( ptTree(tree1), tree1.tpe, if (isSingleType(tree1.tpe)) " with underlying "+tree1.tpe.widen else "") ) - tree1 } tree1 modifyType (addAnnotations(tree1, _)) diff --git a/src/compiler/scala/tools/nsc/util/ClassPath.scala b/src/compiler/scala/tools/nsc/util/ClassPath.scala index cbf6ef69d7..c51fc442dc 100644 --- a/src/compiler/scala/tools/nsc/util/ClassPath.scala +++ b/src/compiler/scala/tools/nsc/util/ClassPath.scala @@ -14,6 +14,7 @@ import scala.reflect.internal.util.StringOps.splitWhere import Jar.isJarOrZip import File.pathSeparator import java.net.MalformedURLException +import java.util.regex.PatternSyntaxException /** <p> * This module provides star expansion of '-classpath' option arguments, behaves the same as @@ -34,8 +35,11 @@ object ClassPath { if (pattern == "*") lsDir(Directory(".")) else if (pattern endsWith wildSuffix) lsDir(Directory(pattern dropRight 2)) else if (pattern contains '*') { - val regexp = ("^%s$" format pattern.replaceAll("""\*""", """.*""")).r - lsDir(Directory(pattern).parent, regexp findFirstIn _ isDefined) + try { + val regexp = ("^" + pattern.replaceAllLiterally("""\*""", """.*""") + "$").r + lsDir(Directory(pattern).parent, regexp findFirstIn _ isDefined) + } + catch { case _: PatternSyntaxException => List(pattern) } } else List(pattern) } |