From b1f070e51379c2d967262e083a352ec1548429ee Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Sun, 13 Jun 2021 18:03:10 +0200 Subject: [PATCH] Plug loophole for "no inlines with opaques" rule Fixes #12814 --- .../src/dotty/tools/dotc/core/SymDenotations.scala | 3 +-- tests/neg/opaque-inline.scala | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 tests/neg/opaque-inline.scala diff --git a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala index ba094c587038..7f81fcf72597 100644 --- a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala @@ -651,8 +651,7 @@ object SymDenotations { def containsOpaques(using Context): Boolean = is(Opaque) && isClass def seesOpaques(using Context): Boolean = - containsOpaques || - is(Module, butNot = Package) && owner.seesOpaques + containsOpaques || isClass && !is(Package) && owner.seesOpaques /** Is this the denotation of a self symbol of some class? * This is the case if one of two conditions holds: diff --git a/tests/neg/opaque-inline.scala b/tests/neg/opaque-inline.scala new file mode 100644 index 000000000000..5507484231dd --- /dev/null +++ b/tests/neg/opaque-inline.scala @@ -0,0 +1,14 @@ + +object refined: + opaque type Positive = Int + + object Positive extends PositiveFactory + + trait PositiveFactory: + inline def apply(value: Int): Positive = f(value) // error: implementation restriction + def f(x: Positive): Positive = x + +@main def run: Unit = + import refined.* + val x = 9 + val nine = Positive.apply(x)