Skip to content

Commit fc8b512

Browse files
authored
Merge pull request #10195 from dotty-staging/fix-#10178
Fix #10178: Put the wildcard demon back in the bottle
2 parents d329c13 + a325641 commit fc8b512

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1456,10 +1456,15 @@ object desugar {
14561456

14571457
/** If `pat` is not an Identifier, a Typed(Ident, _), or a Bind, wrap
14581458
* it in a Bind with a fresh name. Return the transformed pattern, and the identifier
1459-
* that refers to the bound variable for the pattern.
1459+
* that refers to the bound variable for the pattern. Wildcard Binds are
1460+
* also replaced by Binds with fresh names.
14601461
*/
14611462
def makeIdPat(pat: Tree): (Tree, Ident) = pat match {
1462-
case Bind(name, _) => (pat, Ident(name))
1463+
case Bind(name, pat1) =>
1464+
if name == nme.WILDCARD then
1465+
val name = UniqueName.fresh()
1466+
(cpy.Bind(pat)(name, pat1), Ident(name))
1467+
else (pat, Ident(name))
14631468
case id: Ident if isVarPattern(id) && id.name != nme.WILDCARD => (id, id)
14641469
case Typed(id: Ident, _) if isVarPattern(id) && id.name != nme.WILDCARD => (pat, id)
14651470
case _ =>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ class Typer extends Namer
232232
fail(em"reference to `$name` is ambiguous; it is imported twice")
233233
found
234234

235-
if adjustExtension(selector.rename) == termName then
235+
if adjustExtension(selector.rename) == termName && selector.rename != nme.WILDCARD then
236236
val memberName =
237237
if selector.name == termName then name
238238
else if name.isTypeName then selector.name.toTypeName

tests/run/i10178.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@main def Test: Unit =
2+
for
3+
x <- Option(23)
4+
given Int = x
5+
do assert(summon[Int] == 23)

0 commit comments

Comments
 (0)