File tree 3 files changed +10
-18
lines changed
compiler/src/dotty/tools/dotc
3 files changed +10
-18
lines changed Original file line number Diff line number Diff line change @@ -274,27 +274,21 @@ object desugar {
274
274
275
275
/** Transforms a definition with a name starting with a `$` in a quoted pattern into a `quoted.binding.Binding` splice.
276
276
*
277
- * The desugaring consists in renaming the the definition and adding the `@patternBindHole` annotation. This
278
- * annotation is used during typing to perform the full transformation.
277
+ * The desugaring consists in adding the `@patternBindHole` annotation. This annotation is used during typing to perform the full transformation.
279
278
*
280
279
* A definition
281
280
* ```scala
282
- * case '{ def $a(...) = ... a() ... ; ... a () ... }
281
+ * case '{ def $a(...) = ...; ... `$a` () ... } => a
283
282
* ```
284
283
* into
285
284
* ```scala
286
- * case '{ @patternBindHole def a (...) = ... a() ... ; ... a () ... }
285
+ * case '{ @patternBindHole def `$a` (...) = ...; ... `$a` () ... } => a
287
286
* ```
288
287
*/
289
288
def transformQuotedPatternName (tree : ValOrDefDef )(implicit ctx : Context ): ValOrDefDef = {
290
289
if (ctx.mode.is(Mode .QuotedPattern ) && ! tree.isBackquoted && tree.name != nme.ANON_FUN && tree.name.startsWith(" $" )) {
291
- val name = tree.name.toString.substring(1 ).toTermName
292
- val newTree : ValOrDefDef = tree match {
293
- case tree : ValDef => cpy.ValDef (tree)(name)
294
- case tree : DefDef => cpy.DefDef (tree)(name)
295
- }
296
290
val mods = tree.mods.withAddedAnnotation(New (ref(defn.InternalQuoted_patternBindHoleAnnot .typeRef)).withSpan(tree.span))
297
- newTree .withMods(mods)
291
+ tree .withMods(mods)
298
292
} else tree
299
293
}
300
294
Original file line number Diff line number Diff line change @@ -1986,7 +1986,9 @@ class Typer extends Namer
1986
1986
case t => t
1987
1987
}
1988
1988
val bindingExprTpe = AppliedType (defn.QuotedMatchingBindingType , bindingType :: Nil )
1989
- val sym = ctx0.newPatternBoundSymbol(ddef.name, bindingExprTpe, ddef.span)
1989
+ assert(ddef.name.startsWith(" $" ))
1990
+ val bindName = ddef.name.toString.stripPrefix(" $" ).toTermName
1991
+ val sym = ctx0.newPatternBoundSymbol(bindName, bindingExprTpe, ddef.span)
1990
1992
patBuf += Bind (sym, untpd.Ident (nme.WILDCARD ).withType(bindingExprTpe)).withSpan(ddef.span)
1991
1993
}
1992
1994
super .transform(tree)
Original file line number Diff line number Diff line change @@ -12,17 +12,13 @@ object Test {
12
12
case ' { ((a : Int ) => 3 )($y) } => y
13
13
case ' { 1 + ($y : Int )} => y
14
14
case ' { val a = 1 + ($y : Int ); 3 } => y
15
- // currently gives an unreachable case warning
16
- // but only when used in conjunction with the others.
17
- // I believe this is because implicit arguments are not taken
18
- // into account when checking whether we have already seen an `unapply` before.
19
- case ' { val $y : Int = $z; 1 } =>
15
+ case ' { val $y : Int = $z; println(`$y`); 1 } =>
20
16
val a : quoted.matching.Bind [Int ] = y
21
17
z
22
- case ' { (($y : Int ) => 1 + y + ($z : Int ))(2 ) } =>
18
+ case ' { (($y : Int ) => 1 + `$y` + ($z : Int ))(2 ) } =>
23
19
val a : quoted.matching.Bind [Int ] = y
24
20
z
25
- case ' { def $ff : Int = $z; ff } =>
21
+ case ' { def $ff : Int = $z; `$ff` } =>
26
22
val a : quoted.matching.Bind [Int ] = ff
27
23
z
28
24
case ' { def $ff (i : Int ): Int = $z; 2 } =>
You can’t perform that action at this time.
0 commit comments