Skip to content

Commit 2b7a87b

Browse files
committed
Types with only an abstract inline method are not SAMs
Fixes #12556
1 parent 8d3083b commit 2b7a87b

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -947,8 +947,11 @@ object Types {
947947
final def possibleSamMethods(using Context): Seq[SingleDenotation] = {
948948
record("possibleSamMethods")
949949
atPhaseNoLater(erasurePhase) {
950-
abstractTermMembers.toList.filterConserve(m =>
951-
!m.symbol.matchingMember(defn.ObjectType).exists && !m.symbol.isSuperAccessor)
950+
abstractTermMembers.toList.filterConserve { m =>
951+
!m.symbol.matchingMember(defn.ObjectType).exists
952+
&& !m.symbol.isSuperAccessor
953+
&& !m.symbol.isInlineMethod
954+
}
952955
}.map(_.current)
953956
}
954957

@@ -5353,6 +5356,7 @@ object Types {
53535356
*
53545357
* - has a single abstract method with a method type (ExprType
53555358
* and PolyType not allowed!) whose result type is not an implicit function type
5359+
* and which is not marked inline.
53565360
* - can be instantiated without arguments or with just () as argument.
53575361
*
53585362
* The pattern `SAMType(sam)` matches a SAM type, where `sam` is the

tests/neg/i12555b.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import Noop.*
1010

1111
final case class User(name: String, age: Int)
1212

13-
inline given Noop[User] = a => a
13+
inline given Noop[User] = a => a // error
1414

1515
val u = User("hello", 45)
1616

1717
@main
18-
def run = println(Noop.noop(u)) // error
18+
def run = println(Noop.noop(u))

0 commit comments

Comments
 (0)