Spurious Eta expansion warning ScalaJS on Scala 3.4.0?

When compiling the code

import scala.scalajs.js
import org.scalajs.dom.MouseEvent

@js.native
trait MyElement extends js.Object :
  var onclick: js.Function1[MouseEvent, ?] = js.native

object Test :
  def handleInput(me: MouseEvent): Unit = ()
  val input: MyElement = ???
  input.onclick = handleInput _

under Scala 3.4.0 / ScalaJS it gives the deprecation warning:

The syntax `<function> _` is no longer supported;
you can simply leave out the trailing ` _`
This construct can be rewritten automatically under -rewrite -source 3.4-migration.

okay, so we need to remove the _ in the last line, but then we get:

method handleInput is eta-expanded even though scala.scalajs.js.Function1[org.scalajsĀ².dom.MouseEvent, Any] 
does not have the @FunctionalInterface annotation.

where:    scalajs  is a package in package scala
          scalajsĀ² is a package in package org

is this a ā€œSpurious Eta expansion warningā€? Something like this issue?

You can write x => handleInput(x) to avoid the warning, but it seems that the scalajs standard library should be updated to add the @FunctionalInterface annotation to its Function classes /cc @sjrd

1 Like

Iā€™m pretty sure js.FunctionNs cannot have @FunctionalInterface because they extend the class js.Function.

Ah, maybe we need to special-case it in the compiler to silence the warning then.

1 Like