diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index d802ef0df973..628dcc5a9d92 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -989,7 +989,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer def canAssign(sym: Symbol) = sym.is(Mutable, butNot = Accessor) || - ctx.owner.isPrimaryConstructor && !sym.is(Method) && sym.owner == ctx.owner.owner || + ctx.owner.isPrimaryConstructor && !sym.is(Method) && sym.maybeOwner == ctx.owner.owner || // allow assignments from the primary constructor to class fields ctx.owner.name.is(TraitSetterName) || ctx.owner.isStaticConstructor diff --git a/tests/neg/i15897.scala b/tests/neg/i15897.scala new file mode 100644 index 000000000000..d9dbe94c4eef --- /dev/null +++ b/tests/neg/i15897.scala @@ -0,0 +1,8 @@ +object O { + class AC(code: => Unit) + + val action = new AC({mode = ???}) {} // error + + def mode: AnyRef = ??? + def mode=(em: AnyRef): Unit = {} // error // error // error +} \ No newline at end of file diff --git a/tests/pos/i15897.scala b/tests/pos/i15897.scala new file mode 100644 index 000000000000..b039401a6519 --- /dev/null +++ b/tests/pos/i15897.scala @@ -0,0 +1,8 @@ +object O { + class AC(code: => Unit) + + val action = new AC({mode = ???}) {} + + def mode: AnyRef = ??? + def mode_=(em: AnyRef): Unit = {} +} \ No newline at end of file