diff --git a/compiler/src/dotty/tools/dotc/inlines/Inlines.scala b/compiler/src/dotty/tools/dotc/inlines/Inlines.scala index ff08d551ca87..8110fd2de195 100644 --- a/compiler/src/dotty/tools/dotc/inlines/Inlines.scala +++ b/compiler/src/dotty/tools/dotc/inlines/Inlines.scala @@ -229,8 +229,8 @@ object Inlines: val retainer = meth.copy( name = BodyRetainerName(meth.name), - flags = meth.flags &~ (Inline | Macro | Override) | Private, - coord = mdef.rhs.span.startPos).asTerm + flags = (meth.flags &~ (Inline | Macro | Override | AbsOverride)) | Private, + coord = mdef.rhs.span.startPos).asTerm.entered retainer.deriveTargetNameAnnotation(meth, name => BodyRetainerName(name.asTermName)) DefDef(retainer, prefss => inlineCall( diff --git a/compiler/src/dotty/tools/dotc/transform/ExtensionMethods.scala b/compiler/src/dotty/tools/dotc/transform/ExtensionMethods.scala index 7c76211ca8ec..a430f7532066 100644 --- a/compiler/src/dotty/tools/dotc/transform/ExtensionMethods.scala +++ b/compiler/src/dotty/tools/dotc/transform/ExtensionMethods.scala @@ -13,7 +13,7 @@ import core._ import Types._, Contexts._, Names._, Flags._, DenotTransformers._, Phases._ import SymDenotations._, Symbols._, StdNames._, Denotations._ import TypeErasure.{ valueErasure, ErasedValueType } -import NameKinds.ExtMethName +import NameKinds.{ExtMethName, BodyRetainerName} import Decorators._ import TypeUtils._ @@ -79,7 +79,7 @@ class ExtensionMethods extends MiniPhase with DenotTransformer with FullParamete // because it adds extension methods before pickling. if (!(valueClass.is(Scala2x))) for (decl <- valueClass.classInfo.decls) - if (isMethodWithExtension(decl)) + if isMethodWithExtension(decl) then enterInModuleClass(createExtensionMethod(decl, moduleClassSym.symbol)) // Create synthetic methods to cast values between the underlying type @@ -179,7 +179,10 @@ object ExtensionMethods { /** Name of the extension method that corresponds to given instance method `meth`. */ def extensionName(imeth: Symbol)(using Context): TermName = - ExtMethName(imeth.name.asTermName) + ExtMethName( + imeth.name.asTermName match + case BodyRetainerName(name) => name + case name => name) /** Return the extension method that corresponds to given instance method `meth`. */ def extensionMethod(imeth: Symbol)(using Context): TermSymbol = diff --git a/compiler/src/dotty/tools/dotc/transform/ValueClasses.scala b/compiler/src/dotty/tools/dotc/transform/ValueClasses.scala index a86bf2c48fb5..92cbd0e57ac5 100644 --- a/compiler/src/dotty/tools/dotc/transform/ValueClasses.scala +++ b/compiler/src/dotty/tools/dotc/transform/ValueClasses.scala @@ -29,6 +29,7 @@ object ValueClasses { isDerivedValueClass(d.owner) && !d.isConstructor && !d.symbol.isSuperAccessor && + !d.isInlineMethod && !d.is(Macro) } diff --git a/tests/run/i15725.check b/tests/run/i15725.check new file mode 100644 index 000000000000..f4de0404545d --- /dev/null +++ b/tests/run/i15725.check @@ -0,0 +1 @@ +2 meters diff --git a/tests/run/i15725.scala b/tests/run/i15725.scala new file mode 100644 index 000000000000..e285d87bb456 --- /dev/null +++ b/tests/run/i15725.scala @@ -0,0 +1,8 @@ +class ToString(d: Int) extends AnyVal : + inline override def toString():String = s"$d meters" + +@main def Test = + val ts = ToString(2) + val a: Any = ts + println(a) +