From 2b7a87b83b4c86205ff23976cd898550b9120683 Mon Sep 17 00:00:00 2001 From: odersky Date: Thu, 7 Apr 2022 11:35:15 +0200 Subject: [PATCH] Types with only an abstract inline method are not SAMs Fixes #12556 --- compiler/src/dotty/tools/dotc/core/Types.scala | 8 ++++++-- tests/neg/i12555b.scala | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala index c71ad928a7d2..e6ab80afaba5 100644 --- a/compiler/src/dotty/tools/dotc/core/Types.scala +++ b/compiler/src/dotty/tools/dotc/core/Types.scala @@ -947,8 +947,11 @@ object Types { final def possibleSamMethods(using Context): Seq[SingleDenotation] = { record("possibleSamMethods") atPhaseNoLater(erasurePhase) { - abstractTermMembers.toList.filterConserve(m => - !m.symbol.matchingMember(defn.ObjectType).exists && !m.symbol.isSuperAccessor) + abstractTermMembers.toList.filterConserve { m => + !m.symbol.matchingMember(defn.ObjectType).exists + && !m.symbol.isSuperAccessor + && !m.symbol.isInlineMethod + } }.map(_.current) } @@ -5353,6 +5356,7 @@ object Types { * * - has a single abstract method with a method type (ExprType * and PolyType not allowed!) whose result type is not an implicit function type + * and which is not marked inline. * - can be instantiated without arguments or with just () as argument. * * The pattern `SAMType(sam)` matches a SAM type, where `sam` is the diff --git a/tests/neg/i12555b.scala b/tests/neg/i12555b.scala index 5931bda4ba27..651eb0efb7c6 100644 --- a/tests/neg/i12555b.scala +++ b/tests/neg/i12555b.scala @@ -10,9 +10,9 @@ import Noop.* final case class User(name: String, age: Int) -inline given Noop[User] = a => a +inline given Noop[User] = a => a // error val u = User("hello", 45) @main -def run = println(Noop.noop(u)) // error +def run = println(Noop.noop(u))