Skip to content

Types with only an abstract inline method are not SAMs #14874

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/neg/i12555b.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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))