From cb764b04c640d7a8e592876956c0a454567c3281 Mon Sep 17 00:00:00 2001 From: odersky Date: Fri, 11 Mar 2022 14:22:19 +0100 Subject: [PATCH] Generate opaque proxies also for base classes Fixes #14656 --- compiler/src/dotty/tools/dotc/typer/Inliner.scala | 2 +- tests/pos/i14656.scala | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 tests/pos/i14656.scala diff --git a/compiler/src/dotty/tools/dotc/typer/Inliner.scala b/compiler/src/dotty/tools/dotc/typer/Inliner.scala index 0a762356869f..b4dda58e6a17 100644 --- a/compiler/src/dotty/tools/dotc/typer/Inliner.scala +++ b/compiler/src/dotty/tools/dotc/typer/Inliner.scala @@ -597,7 +597,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) { def addOpaqueProxies(tp: Type, span: Span, forThisProxy: Boolean)(using Context): Unit = tp.foreachPart { case ref: TermRef => - for cls <- ref.widen.classSymbols do + for cls <- ref.widen.baseClasses do if cls.containsOpaques && (forThisProxy || inlinedMethod.isContainedIn(cls)) && mapRef(ref).isEmpty diff --git a/tests/pos/i14656.scala b/tests/pos/i14656.scala new file mode 100644 index 000000000000..9f5e11a71116 --- /dev/null +++ b/tests/pos/i14656.scala @@ -0,0 +1,12 @@ + +trait BigDecimalNewType: + opaque type Type = BigDecimal + def apply(value: BigDecimal): Type = value + extension (self: Type) + def value: BigDecimal = self + inline def +(y: Type): Type = apply(self.value + y.value) + +object Amount extends BigDecimalNewType { + val x = Amount(0) + val y = (x + x) + x +} \ No newline at end of file