Skip to content

Commit 80cf18f

Browse files
Add safety checks to samMethod
`sam` in `samMethod` stands for "single abstract method". However, presently, no check is performed to verify that the abstract method it finds is indeed single. This commit adds such a check to this method.
1 parent 574fd0c commit 80cf18f

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -853,8 +853,12 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
853853

854854
def addRemoteRemoteExceptionAnnotation: Unit = ()
855855

856-
def samMethod(): Symbol =
857-
toDenot(sym).info.abstractTermMembers.headOption.getOrElse(toDenot(sym).info.member(nme.apply)).symbol
856+
def samMethod(): Symbol = {
857+
val abstractTermMembers = toDenot(sym).info.abstractTermMembers
858+
if (abstractTermMembers.size > 1) abort(s"${sym.show} is not a functional interface. " +
859+
s"It has the following abstract methods: ${abstractTermMembers.map(_.name).mkString(", ")}")
860+
else abstractTermMembers.headOption.getOrElse(toDenot(sym).info.member(nme.apply)).symbol
861+
}
858862

859863
def isFunctionClass: Boolean =
860864
defn.isFunctionClass(sym)

0 commit comments

Comments
 (0)