Skip to content

Fix #947 #962

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

Merged
merged 6 commits into from
Nov 17, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/dotty/tools/dotc/ast/Desugar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 8 additions & 3 deletions src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]]
Expand Down
4 changes: 3 additions & 1 deletion test/dotc/scala-collections.whitelist
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions tests/pos/i947.scala
Original file line number Diff line number Diff line change
@@ -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
}


}
}
6 changes: 6 additions & 0 deletions tests/pos/implicits2.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}
}