File tree Expand file tree Collapse file tree 3 files changed +10
-18
lines changed
compiler/src/dotty/tools/dotc Expand file tree Collapse file tree 3 files changed +10
-18
lines changed Original file line number Diff line number Diff line change @@ -274,27 +274,21 @@ object desugar {
274274
275275 /** Transforms a definition with a name starting with a `$` in a quoted pattern into a `quoted.binding.Binding` splice.
276276 *
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.
279278 *
280279 * A definition
281280 * ```scala
282- * case '{ def $a(...) = ... a() ... ; ... a () ... }
281+ * case '{ def $a(...) = ...; ... `$a` () ... } => a
283282 * ```
284283 * into
285284 * ```scala
286- * case '{ @patternBindHole def a (...) = ... a() ... ; ... a () ... }
285+ * case '{ @patternBindHole def `$a` (...) = ...; ... `$a` () ... } => a
287286 * ```
288287 */
289288 def transformQuotedPatternName (tree : ValOrDefDef )(implicit ctx : Context ): ValOrDefDef = {
290289 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- }
296290 val mods = tree.mods.withAddedAnnotation(New (ref(defn.InternalQuoted_patternBindHoleAnnot .typeRef)).withSpan(tree.span))
297- newTree .withMods(mods)
291+ tree .withMods(mods)
298292 } else tree
299293 }
300294
Original file line number Diff line number Diff line change @@ -1986,7 +1986,9 @@ class Typer extends Namer
19861986 case t => t
19871987 }
19881988 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)
19901992 patBuf += Bind (sym, untpd.Ident (nme.WILDCARD ).withType(bindingExprTpe)).withSpan(ddef.span)
19911993 }
19921994 super .transform(tree)
Original file line number Diff line number Diff line change @@ -12,17 +12,13 @@ object Test {
1212 case ' { ((a : Int ) => 3 )($y) } => y
1313 case ' { 1 + ($y : Int )} => y
1414 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 } =>
2016 val a : quoted.matching.Bind [Int ] = y
2117 z
22- case ' { (($y : Int ) => 1 + y + ($z : Int ))(2 ) } =>
18+ case ' { (($y : Int ) => 1 + `$y` + ($z : Int ))(2 ) } =>
2319 val a : quoted.matching.Bind [Int ] = y
2420 z
25- case ' { def $ff : Int = $z; ff } =>
21+ case ' { def $ff : Int = $z; `$ff` } =>
2622 val a : quoted.matching.Bind [Int ] = ff
2723 z
2824 case ' { def $ff (i : Int ): Int = $z; 2 } =>
You can’t perform that action at this time.
0 commit comments