E099: Only Functions Can Be Followed By Underscore
This error is emitted when the eta-expansion syntax x _ is used on an expression that is not a method.
The syntax x _ for converting a method to a function value is deprecated and only works with methods. For non-method expressions, you need to explicitly write () => x to create a function value.
Example
val x = 42
val f = x _
Error
-- [E099] Syntax Error: example.scala:2:10 -------------------------------------
2 |val f = x _
| ^^^
|Only function types can be followed by _ but the current expression has type Int
|-----------------------------------------------------------------------------
| Explanation (enabled by `-explain`)
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| The syntax x _ is no longer supported if x is not a function.
| To convert to a function value, you need to explicitly write () => x
-----------------------------------------------------------------------------
Solution
// Use explicit function syntax
val x = 42
val f = () => x
In this article