Skip to content

Commit 57376a7

Browse files
committed
Infer Local for val constructor params
1 parent 60e421b commit 57376a7

File tree

7 files changed

+16
-7
lines changed

7 files changed

+16
-7
lines changed

compiler/src/dotty/tools/dotc/core/Flags.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,9 @@ object Flags {
440440
*/
441441
val (PhantomSymbol @ _, _, _) = newFlags(62, "<phantom symbol>") // (could be merged with Lifted)
442442

443+
444+
val (ValMember @ _, _, _) = newFlags(63, "<val>") // (could be merged with Lifted)
445+
443446
// --------- Combined Flag Sets and Conjunctions ----------------------
444447

445448
/** All possible flags */

compiler/src/dotty/tools/dotc/core/SymDenotations.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2694,7 +2694,7 @@ object SymDenotations {
26942694
* determined by whether they have a `val` or `var` or not.
26952695
*/
26962696
def canBeLocal(name: Name, flags: FlagSet)(using Context) =
2697-
!name.isConstructorName && !flags.is(Param) && !flags.is(ParamAccessor)
2697+
!name.isConstructorName && !flags.is(ValMember)
26982698

26992699
/** Factory method for SymDenotion creation. All creations
27002700
* should be done via this method.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3679,7 +3679,7 @@ object Parsers {
36793679
if (!(mods.flags &~ (ParamAccessor | Inline | Erased | impliedMods.flags)).isEmpty)
36803680
syntaxError(em"`val` or `var` expected")
36813681
if firstClause && paramOwner == ParamOwner.CaseClass then mods
3682-
else mods | PrivateLocal
3682+
else mods | PrivateLocal | ValMember
36833683
else {
36843684
if (isIdent(nme.inline) && in.isSoftModifierInParamModifierPosition)
36853685
mods = addModifier(mods)

tests/neg/i22620.scala

Lines changed: 0 additions & 4 deletions
This file was deleted.

tests/pos/i22620.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import scala.collection.mutable.ArrayBuffer
2+
3+
class PrivateTest[-M](private val v: ArrayBuffer[M])

tests/pos/i22620b.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
sealed abstract class Tree[+A](
2+
final val key: A
3+
)
4+
final class RedTree[+A](key: A) extends Tree[A](key)
5+
object RedTree {
6+
def unapply[A](t: RedTree[A]) = Some((t.key))
7+
}

tests/warn/i15503c.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ package foo.test.constructors:
3636
case class A private (x: Int) // OK
3737
class B private (val x: Int) // OK
3838
object B { def default = B(42) }
39-
class C private (private val xy: Int) // warn
39+
class C private (private val xy: Int)
4040
object C { def default = C(42) }
4141
class D private (private val x: Int): // OK
4242
def y = x

0 commit comments

Comments
 (0)