diff --git a/src/dotty/tools/dotc/ast/Desugar.scala b/src/dotty/tools/dotc/ast/Desugar.scala index 6c914c934539..327b39897f94 100644 --- a/src/dotty/tools/dotc/ast/Desugar.scala +++ b/src/dotty/tools/dotc/ast/Desugar.scala @@ -517,6 +517,12 @@ object desugar { } } + /** Expand variable identifier x to x @ _ */ + def patternVar(tree: Tree)(implicit ctx: Context) = { + val Ident(name) = tree + Bind(name, Ident(nme.WILDCARD)).withPos(tree.pos) + } + def defTree(tree: Tree)(implicit ctx: Context): Tree = tree match { case tree: ValDef => valDef(tree) case tree: TypeDef => if (tree.isClassDef) classDef(tree) else typeDef(tree) diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala index d54c9f7314ba..0ae04cbe84da 100644 --- a/src/dotty/tools/dotc/typer/Typer.scala +++ b/src/dotty/tools/dotc/typer/Typer.scala @@ -253,8 +253,8 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit if (ctx.mode is Mode.Pattern) { if (name == nme.WILDCARD) return tree.withType(pt) - if (isVarPattern(tree)) - return typed(untpd.Bind(name, untpd.Ident(nme.WILDCARD)).withPos(tree.pos), pt) + if (isVarPattern(tree) && name.isTermName) + return typed(desugar.patternVar(tree), pt) } val saved = importedFromRoot @@ -848,7 +848,12 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit args = args.take(tparams.length) } def typedArg(arg: untpd.Tree, tparam: Symbol) = { - val arg1 = typed(arg, if (ctx.mode is Mode.Pattern) tparam.info else WildcardType) + val (desugaredArg, argPt) = + if (ctx.mode is Mode.Pattern) + (if (isVarPattern(arg)) desugar.patternVar(arg) else arg, tparam.info) + else + (arg, WildcardType) + val arg1 = typed(desugaredArg, argPt) adaptTypeArg(arg1, if (tparam.isCompleted) tparam.info else WildcardType) } val args1 = args.zipWithConserve(tparams)(typedArg(_, _)).asInstanceOf[List[Tree]] diff --git a/test/dotc/scala-collections.whitelist b/test/dotc/scala-collections.whitelist index 6c4a34f0e359..70d3388d1f0b 100644 --- a/test/dotc/scala-collections.whitelist +++ b/test/dotc/scala-collections.whitelist @@ -86,6 +86,8 @@ #./scala-scala/src/library/scala/collection/mutable/IndexedSeq.scala #./scala-scala/src/library/scala/collection/mutable/ListBuffer.scala +./scala-scala/src/library/scala/collection/mutable/ArrayBuilder.scala + ./scala-scala/src/library/scala/collection/immutable/Stack.scala ./scala-scala/src/library/scala/collection/immutable/StringLike.scala ./scala-scala/src/library/scala/collection/immutable/StringOps.scala @@ -167,7 +169,7 @@ ./scala-scala/src/library/scala/collection/SeqExtractors.scala # https://github.com/lampepfl/dotty/issues/945 -#./scala-scala/src/library/scala/collection/SeqLike.scala +./scala-scala/src/library/scala/collection/SeqLike.scala ./scala-scala/src/library/scala/collection/SeqProxy.scala ./scala-scala/src/library/scala/collection/SeqProxyLike.scala diff --git a/tests/pos/i947.scala b/tests/pos/i947.scala new file mode 100644 index 000000000000..0f2d9e77583a --- /dev/null +++ b/tests/pos/i947.scala @@ -0,0 +1,16 @@ +object Test { + + class c { + + private var x: Int = 0 + + override def equals(other: Any) = other match { + case o: c => x == o.x + case xs: List[c] => false + case ys: List[d18383] => false + case _ => false + } + + + } +} diff --git a/tests/pos/implicits2.scala b/tests/pos/implicits2.scala index 8e566c19f2d8..a201ed5f9e1a 100644 --- a/tests/pos/implicits2.scala +++ b/tests/pos/implicits2.scala @@ -16,4 +16,10 @@ object implicits2 { val x: scala.collection.immutable.WrappedString = "abc" + implicit val (xx: String, y: Int) = ("a", 22) + + def main(args: Array[String]) = { + println(implicitly[String]) + println(implicitly[Int]) + } }