From 7aa01b80a234f0a1d4cf06c71aa04159fc8bf724 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Wed, 8 Nov 2023 10:57:00 +0100 Subject: [PATCH] Desugar `lazy val` pattern bindings into `lazy val`s Fixes #18878 Reverts change in 54f6399b6625cb8f841c1e5965841d46a3e9230c Example: ``` lazy val (a, b) = ... ``` desugars into ``` private lazy val t$1 = ... lazy val a = t$1._1 // before: def a = t$1._1 lazy val b = t$1._2 // before: def b = t$1._2 ``` Where `a` and `b` should be stable identifiers. --- compiler/src/dotty/tools/dotc/ast/Desugar.scala | 13 ++++--------- tests/pos/i18878.scala | 6 ++++++ 2 files changed, 10 insertions(+), 9 deletions(-) create mode 100644 tests/pos/i18878.scala diff --git a/compiler/src/dotty/tools/dotc/ast/Desugar.scala b/compiler/src/dotty/tools/dotc/ast/Desugar.scala index 0607b3729654..7feb727df403 100644 --- a/compiler/src/dotty/tools/dotc/ast/Desugar.scala +++ b/compiler/src/dotty/tools/dotc/ast/Desugar.scala @@ -1311,16 +1311,11 @@ object desugar { val restDefs = for (((named, tpt), n) <- vars.zipWithIndex if named.name != nme.WILDCARD) yield - if mods.is(Lazy) then - DefDef(named.name.asTermName, Nil, tpt, selector(n)) - .withMods(mods &~ Lazy) + valDef( + ValDef(named.name.asTermName, tpt, selector(n)) + .withMods(mods) .withSpan(named.span) - else - valDef( - ValDef(named.name.asTermName, tpt, selector(n)) - .withMods(mods) - .withSpan(named.span) - ) + ) flatTree(firstDef :: restDefs) } } diff --git a/tests/pos/i18878.scala b/tests/pos/i18878.scala new file mode 100644 index 000000000000..9f16983c8241 --- /dev/null +++ b/tests/pos/i18878.scala @@ -0,0 +1,6 @@ +object Foo: + lazy val (a, (b, c), d) = (1, (2, 3), 4) + def a2: a.type = a + def b2: b.type = b + def c2: c.type = c + def d2: d.type = d