Skip to content

Commit 14066d6

Browse files
authored
Merge pull request #8402 from som-snytt/forward/11437
RHS of var def is an expr
2 parents a7a81d6 + 215d53f commit 14066d6

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3146,14 +3146,15 @@ object Parsers {
31463146
}
31473147
else emptyType
31483148
val rhs =
3149-
if (tpt.isEmpty || in.token == EQUALS)
3149+
if tpt.isEmpty || in.token == EQUALS then
31503150
endMarkerScope(first) {
31513151
accept(EQUALS)
3152-
if (in.token == USCORE && !tpt.isEmpty && mods.is(Mutable) &&
3153-
(lhs.toList forall (_.isInstanceOf[Ident])))
3154-
wildcardIdent()
3155-
else
3156-
subExpr()
3152+
subExpr() match
3153+
case rhs0 @ Ident(name) if placeholderParams.nonEmpty && name == placeholderParams.head.name
3154+
&& !tpt.isEmpty && mods.is(Mutable) && lhs.forall(_.isInstanceOf[Ident]) =>
3155+
placeholderParams = placeholderParams.tail
3156+
atSpan(rhs0.span) { Ident(nme.WILDCARD) }
3157+
case rhs0 => rhs0
31573158
}
31583159
else EmptyTree
31593160
lhs match {

tests/neg/t11437.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
class Regress {
3+
var v: Int = _
4+
def f = 42
5+
var w: Int = (_) // error: not default value syntax
6+
}

tests/pos/t11437.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
trait T {
3+
val adder0: Int => Int = _ + 3 // Works fine
4+
var adder1: Int => Int = (_ + 3) // Works fine
5+
var adder2: Int => Int = _ + 3 // was: Error
6+
}
7+
class Regress {
8+
var v: Int = _
9+
def f = 42
10+
//var w: Int = (_) //Unbound placeholder parameter; incorrect use of _
11+
}

0 commit comments

Comments
 (0)