Skip to content

Commit f9c8675

Browse files
committed
Merge pull request #962 from dotty-staging/fix-#947
Fix #947
2 parents 6b061b5 + c595c56 commit f9c8675

File tree

5 files changed

+39
-4
lines changed

5 files changed

+39
-4
lines changed

src/dotty/tools/dotc/ast/Desugar.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,12 @@ object desugar {
517517
}
518518
}
519519

520+
/** Expand variable identifier x to x @ _ */
521+
def patternVar(tree: Tree)(implicit ctx: Context) = {
522+
val Ident(name) = tree
523+
Bind(name, Ident(nme.WILDCARD)).withPos(tree.pos)
524+
}
525+
520526
def defTree(tree: Tree)(implicit ctx: Context): Tree = tree match {
521527
case tree: ValDef => valDef(tree)
522528
case tree: TypeDef => if (tree.isClassDef) classDef(tree) else typeDef(tree)

src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,8 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
253253
if (ctx.mode is Mode.Pattern) {
254254
if (name == nme.WILDCARD)
255255
return tree.withType(pt)
256-
if (isVarPattern(tree))
257-
return typed(untpd.Bind(name, untpd.Ident(nme.WILDCARD)).withPos(tree.pos), pt)
256+
if (isVarPattern(tree) && name.isTermName)
257+
return typed(desugar.patternVar(tree), pt)
258258
}
259259

260260
val saved = importedFromRoot
@@ -848,7 +848,12 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
848848
args = args.take(tparams.length)
849849
}
850850
def typedArg(arg: untpd.Tree, tparam: Symbol) = {
851-
val arg1 = typed(arg, if (ctx.mode is Mode.Pattern) tparam.info else WildcardType)
851+
val (desugaredArg, argPt) =
852+
if (ctx.mode is Mode.Pattern)
853+
(if (isVarPattern(arg)) desugar.patternVar(arg) else arg, tparam.info)
854+
else
855+
(arg, WildcardType)
856+
val arg1 = typed(desugaredArg, argPt)
852857
adaptTypeArg(arg1, if (tparam.isCompleted) tparam.info else WildcardType)
853858
}
854859
val args1 = args.zipWithConserve(tparams)(typedArg(_, _)).asInstanceOf[List[Tree]]

test/dotc/scala-collections.whitelist

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@
8686
#./scala-scala/src/library/scala/collection/mutable/IndexedSeq.scala
8787
#./scala-scala/src/library/scala/collection/mutable/ListBuffer.scala
8888

89+
./scala-scala/src/library/scala/collection/mutable/ArrayBuilder.scala
90+
8991
./scala-scala/src/library/scala/collection/immutable/Stack.scala
9092
./scala-scala/src/library/scala/collection/immutable/StringLike.scala
9193
./scala-scala/src/library/scala/collection/immutable/StringOps.scala
@@ -167,7 +169,7 @@
167169
./scala-scala/src/library/scala/collection/SeqExtractors.scala
168170

169171
# https://github.com/lampepfl/dotty/issues/945
170-
#./scala-scala/src/library/scala/collection/SeqLike.scala
172+
./scala-scala/src/library/scala/collection/SeqLike.scala
171173

172174
./scala-scala/src/library/scala/collection/SeqProxy.scala
173175
./scala-scala/src/library/scala/collection/SeqProxyLike.scala

tests/pos/i947.scala

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
object Test {
2+
3+
class c {
4+
5+
private var x: Int = 0
6+
7+
override def equals(other: Any) = other match {
8+
case o: c => x == o.x
9+
case xs: List[c] => false
10+
case ys: List[d18383] => false
11+
case _ => false
12+
}
13+
14+
15+
}
16+
}

tests/pos/implicits2.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,10 @@ object implicits2 {
1616

1717
val x: scala.collection.immutable.WrappedString = "abc"
1818

19+
implicit val (xx: String, y: Int) = ("a", 22)
20+
21+
def main(args: Array[String]) = {
22+
println(implicitly[String])
23+
println(implicitly[Int])
24+
}
1925
}

0 commit comments

Comments
 (0)