From 8b8c3ea0c07d05ae41cd88540d8b66a440233f3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Kozak?= Date: Fri, 27 Mar 2026 12:18:44 +0100 Subject: [PATCH] fix: 24765 SAM conversion fails with "cannot override an extension method" for Self-based type classes --- compiler/src/dotty/tools/dotc/ast/tpd.scala | 4 ++-- tests/pos/i24765.scala | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 tests/pos/i24765.scala diff --git a/compiler/src/dotty/tools/dotc/ast/tpd.scala b/compiler/src/dotty/tools/dotc/ast/tpd.scala index b7827724bd7e..27f2cd349976 100644 --- a/compiler/src/dotty/tools/dotc/ast/tpd.scala +++ b/compiler/src/dotty/tools/dotc/ast/tpd.scala @@ -398,8 +398,8 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo { if !overridden.is(Deferred) then fwdMeth.setFlag(Override) DefDef(fwdMeth, ref(fn).appliedToArgss(_)) } - termForwarders.map((name, sym) => forwarder(name, sym)) ++ - typeMembers.map((name, info) => TypeDef(newSymbol(cls, name, Synthetic, info).entered)) + val typeDefs = typeMembers.map((name, info) => TypeDef(newSymbol(cls, name, Synthetic, info).entered)) + termForwarders.map((name, sym) => forwarder(name, sym)) ++ typeDefs } } diff --git a/tests/pos/i24765.scala b/tests/pos/i24765.scala new file mode 100644 index 000000000000..78c67123fc0f --- /dev/null +++ b/tests/pos/i24765.scala @@ -0,0 +1,12 @@ +import language.experimental.modularity + +trait A[T]: + extension(t: T) def foo: T + +trait B: + type Self + extension(t: Self) def foo: Self + +given A[Int] = x => x // ok before + +given Int is B = x => x // was: "cannot override an extension method"