Skip to content

Commit fcf62e1

Browse files
authored
Merge pull request #14906 from dotty-staging/change-wildcard-vals
Allow multiple wildcard vals
2 parents 1503044 + dad8e33 commit fcf62e1

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import core._
66
import util.Spans._, Types._, Contexts._, Constants._, Names._, NameOps._, Flags._
77
import Symbols._, StdNames._, Trees._, ContextOps._
88
import Decorators._, transform.SymUtils._
9-
import NameKinds.{UniqueName, EvidenceParamName, DefaultGetterName}
9+
import NameKinds.{UniqueName, EvidenceParamName, DefaultGetterName, WildcardParamName}
1010
import typer.{Namer, Checking}
1111
import util.{Property, SourceFile, SourcePosition, Chars}
1212
import config.Feature.{sourceVersion, migrateTo3, enabled}
@@ -1109,8 +1109,12 @@ object desugar {
11091109
* ValDef or DefDef.
11101110
*/
11111111
def makePatDef(original: Tree, mods: Modifiers, pat: Tree, rhs: Tree)(using Context): Tree = pat match {
1112-
case IdPattern(named, tpt) =>
1113-
derivedValDef(original, named, tpt, rhs, mods)
1112+
case IdPattern(id, tpt) =>
1113+
val id1 =
1114+
if id.name == nme.WILDCARD
1115+
then cpy.Ident(id)(WildcardParamName.fresh())
1116+
else id
1117+
derivedValDef(original, id1, tpt, rhs, mods)
11141118
case _ =>
11151119

11161120
def filterWildcardGivenBinding(givenPat: Bind): Boolean =

tests/run/wildcard-vals.scala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
object O:
2+
val _ = 1
3+
val _ = 2
4+
val _: Int = 3
5+
val _: Int = 4
6+
def x = 2
7+
8+
@main def Test =
9+
assert(O.x == 2)
10+
val _ = 1
11+
val _ = 2
12+
val _: Int = 3
13+
val _: Int = 4
14+

0 commit comments

Comments
 (0)