diff --git a/compiler/src/dotty/tools/dotc/typer/PrepareInlineable.scala b/compiler/src/dotty/tools/dotc/typer/PrepareInlineable.scala index 5d45d1dce714..a974df67fe1b 100644 --- a/compiler/src/dotty/tools/dotc/typer/PrepareInlineable.scala +++ b/compiler/src/dotty/tools/dotc/typer/PrepareInlineable.scala @@ -54,7 +54,7 @@ object PrepareInlineable { abstract class MakeInlineableMap(val inlineSym: Symbol) extends TreeMap with Insert { def accessorNameOf(name: TermName, site: Symbol)(using Context): TermName = val accName = InlineAccessorName(name) - if site.is(Trait) then accName.expandedName(site) else accName + if site.isExtensibleClass then accName.expandedName(site) else accName /** A definition needs an accessor if it is private, protected, or qualified private * and it is not part of the tree that gets inlined. The latter test is implemented diff --git a/tests/neg/i15323.scala b/tests/neg/i15323.scala deleted file mode 100644 index 3d25156fbcbf..000000000000 --- a/tests/neg/i15323.scala +++ /dev/null @@ -1,11 +0,0 @@ -class A: - private var x = 0 - inline def f1(): Int = - x += 1; - x - -class B extends A: - private var x = 0 // error - inline def f2(): Int = - x += 1 - x diff --git a/tests/pos/i15612.scala b/tests/pos/i15612.scala new file mode 100644 index 000000000000..b05d847dce1e --- /dev/null +++ b/tests/pos/i15612.scala @@ -0,0 +1,23 @@ +import scala.reflect.TypeTest + +class ForSyntax[E](using E: TypeTest[E | Any, E]): + extension [A](aOrE: E | A) + inline def flatMap[B](f: A => E | B): E | B = + aOrE match + case e: E => ??? + case _ => ??? + + +class UnhappyCase[E](using E: TypeTest[E | Any, E]) extends ForSyntax[E]: + extension [A](aOrE: E | A) + inline def fold[B](inline fe: E => B, inline fa: A => B): B = + aOrE match + case e: E => ??? + case _ => ??? + +class A: + private val a = 1 + inline def foo() = a +class B extends A: + private val a = 2 + inline def bar() = a diff --git a/tests/run-macros/i5119.check b/tests/run-macros/i5119.check index 25a27ca667e9..2ba1156be790 100644 --- a/tests/run-macros/i5119.check +++ b/tests/run-macros/i5119.check @@ -1,2 +1,2 @@ -Select(Typed(Apply(Select(New(TypeIdent("StringContextOps")), ""), List(Apply(Select(Select(Select(Ident("_root_"), "scala"), "StringContext"), "apply"), List(Typed(Repeated(List(Literal(StringConstant("Hello World ")), Literal(StringConstant("!"))), Inferred()), Inferred()))))), TypeIdent("StringContextOps")), "inline$sc") +Select(Typed(Apply(Select(New(TypeIdent("StringContextOps")), ""), List(Apply(Select(Select(Select(Ident("_root_"), "scala"), "StringContext"), "apply"), List(Typed(Repeated(List(Literal(StringConstant("Hello World ")), Literal(StringConstant("!"))), Inferred()), Inferred()))))), TypeIdent("StringContextOps")), "Macro$StringContextOps$$inline$sc") Typed(Repeated(List(Literal(IntConstant(1))), Inferred()), Inferred())