Skip to content

Allow multiple wildcard vals #14906

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 1 commit into from
Apr 13, 2022
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
10 changes: 7 additions & 3 deletions compiler/src/dotty/tools/dotc/ast/Desugar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import core._
import util.Spans._, Types._, Contexts._, Constants._, Names._, NameOps._, Flags._
import Symbols._, StdNames._, Trees._, ContextOps._
import Decorators._, transform.SymUtils._
import NameKinds.{UniqueName, EvidenceParamName, DefaultGetterName}
import NameKinds.{UniqueName, EvidenceParamName, DefaultGetterName, WildcardParamName}
import typer.{Namer, Checking}
import util.{Property, SourceFile, SourcePosition, Chars}
import config.Feature.{sourceVersion, migrateTo3, enabled}
Expand Down Expand Up @@ -1109,8 +1109,12 @@ object desugar {
* ValDef or DefDef.
*/
def makePatDef(original: Tree, mods: Modifiers, pat: Tree, rhs: Tree)(using Context): Tree = pat match {
case IdPattern(named, tpt) =>
derivedValDef(original, named, tpt, rhs, mods)
case IdPattern(id, tpt) =>
val id1 =
if id.name == nme.WILDCARD
then cpy.Ident(id)(WildcardParamName.fresh())
else id
derivedValDef(original, id1, tpt, rhs, mods)
case _ =>

def filterWildcardGivenBinding(givenPat: Bind): Boolean =
Expand Down
14 changes: 14 additions & 0 deletions tests/run/wildcard-vals.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
object O:
val _ = 1
val _ = 2
val _: Int = 3
val _: Int = 4
def x = 2

@main def Test =
assert(O.x == 2)
val _ = 1
val _ = 2
val _: Int = 3
val _: Int = 4