diff --git a/compiler/src/dotty/tools/dotc/core/Flags.scala b/compiler/src/dotty/tools/dotc/core/Flags.scala index 8d69917c8189..c1dcfe8ecacd 100644 --- a/compiler/src/dotty/tools/dotc/core/Flags.scala +++ b/compiler/src/dotty/tools/dotc/core/Flags.scala @@ -404,8 +404,8 @@ object Flags { * an existentially bound symbol (Scala 2.x only) */ val (Scala2SpecialFlags @ _, Scala2SuperAccessor @ _, Scala2Existential @ _) = newFlags(55, "") - /** Children were queried on this class */ - val (_, _, ChildrenQueried @ _) = newFlags(56, "") + /** A class parameter that is not a `val` / Children were queried on this class */ + val (_, NotAField @ _, ChildrenQueried @ _) = newFlags(56, "", "") /** A module variable (Scala 2.x only) / a capture-checked class * (Scala2ModuleVar is re-used as a flag for private parameter accessors in Recheck) @@ -475,7 +475,7 @@ object Flags { Scala2SpecialFlags, MutableOrOpen, Opaque, Touched, JavaStatic, OuterOrCovariant, LabelOrContravariant, CaseAccessor, Tracked, Extension, NonMember, Implicit, Given, Permanent, Synthetic, Exported, - SuperParamAliasOrScala2x, Inline, Macro, PhantomSymbol, Invisible) + SuperParamAliasOrScala2x, Inline, Macro, PhantomSymbol, Invisible, NotAField) /** Flags that are not (re)set when completing the denotation, or, if symbol is * a top-level class or object, when completing the denotation once the class diff --git a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala index d534db7df1ce..7461ec7c24b6 100644 --- a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala @@ -2694,7 +2694,7 @@ object SymDenotations { * determined by whether they have a `val` or `var` or not. */ def canBeLocal(name: Name, flags: FlagSet)(using Context) = - !name.isConstructorName && !flags.is(Param) && !flags.is(ParamAccessor) + !name.isConstructorName && !flags.is(NotAField) /** Factory method for SymDenotion creation. All creations * should be done via this method. diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index 77369c828113..0dfdb1708d73 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -3679,7 +3679,7 @@ object Parsers { if (!(mods.flags &~ (ParamAccessor | Inline | Erased | impliedMods.flags)).isEmpty) syntaxError(em"`val` or `var` expected") if firstClause && paramOwner == ParamOwner.CaseClass then mods - else mods | PrivateLocal + else mods | PrivateLocal | NotAField else { if (isIdent(nme.inline) && in.isSoftModifierInParamModifierPosition) mods = addModifier(mods) diff --git a/tests/neg/i22620.scala b/tests/neg/i22620.scala deleted file mode 100644 index 97d1d55e3302..000000000000 --- a/tests/neg/i22620.scala +++ /dev/null @@ -1,4 +0,0 @@ - -import scala.collection.mutable.ArrayBuffer - -class PrivateTest[-M](private val v: ArrayBuffer[M]) // error diff --git a/tests/pos/i22620.scala b/tests/pos/i22620.scala new file mode 100644 index 000000000000..a990cf76c667 --- /dev/null +++ b/tests/pos/i22620.scala @@ -0,0 +1,3 @@ +import scala.collection.mutable.ArrayBuffer + +class PrivateTest[-M](private val v: ArrayBuffer[M]) diff --git a/tests/pos/i22620b.scala b/tests/pos/i22620b.scala new file mode 100644 index 000000000000..afc86c8265f0 --- /dev/null +++ b/tests/pos/i22620b.scala @@ -0,0 +1,7 @@ +sealed abstract class Tree[+A]( + final val key: A +) +final class RedTree[+A](key: A) extends Tree[A](key) +object RedTree { + def unapply[A](t: RedTree[A]) = Some((t.key)) +} diff --git a/tests/semanticdb/metac.expect b/tests/semanticdb/metac.expect index a8ed97afe126..62d0b744f2ae 100644 --- a/tests/semanticdb/metac.expect +++ b/tests/semanticdb/metac.expect @@ -626,7 +626,7 @@ classes/C6#``().(x) => param x: Int classes/C6#copy$default$1(). => method copy$default$1 => Int @uncheckedVariance classes/C6#copy(). => method copy (param x: Int): C6 classes/C6#copy().(x) => param x: Int -classes/C6#x. => private val method x Int +classes/C6#x. => private[this] val method x Int classes/C6. => final object C6 extends Object { self: C6.type => +4 decls } classes/C6.apply(). => method apply (param x: Int): C6 classes/C6.apply().(x) => param x: Int @@ -1957,7 +1957,7 @@ example/ImplicitConversion.newAny2stringadd#`+`(). => method + (param other: Str example/ImplicitConversion.newAny2stringadd#`+`().(other) => param other: String example/ImplicitConversion.newAny2stringadd#``(). => primary ctor [typeparam A ](param self: A): newAny2stringadd[A] example/ImplicitConversion.newAny2stringadd#``().(self) => param self: A -example/ImplicitConversion.newAny2stringadd#self. => private val method self A +example/ImplicitConversion.newAny2stringadd#self. => private[this] val method self A example/ImplicitConversion.newAny2stringadd(). => final implicit method newAny2stringadd [typeparam A ](param self: A): newAny2stringadd[A] example/ImplicitConversion.newAny2stringadd().(self) => param self: A example/ImplicitConversion.newAny2stringadd().[A] => typeparam A diff --git a/tests/warn/i15503c.scala b/tests/warn/i15503c.scala index 86b972487e17..97f87c941678 100644 --- a/tests/warn/i15503c.scala +++ b/tests/warn/i15503c.scala @@ -36,7 +36,7 @@ package foo.test.constructors: case class A private (x: Int) // OK class B private (val x: Int) // OK object B { def default = B(42) } - class C private (private val xy: Int) // warn + class C private (private val xy: Int) object C { def default = C(42) } class D private (private val x: Int): // OK def y = x