-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Open
Description
Compiler version
3.7.3-RC1
Minimized code
extension (long1: Option[Long])
def +(long2: Option[Long]): Option[Long] = (long1, long2) match
case (Some(long1), Some(long2)) => Some(long1 + long2)
case (Some(long1), None) => Some(long1)
case (None, Some(long2)) => Some(long2)
case (None, None) => None
case class Price(usd: Option[Long] = None)
object Price:
extension (price1: Price)
def +(price2: Price): Price = Price(usd = price1.usd + price2.usd)https://scastie.scala-lang.org/09Hol8TDSl6bNeMjvcW6bw
Output
value + is not a member of Option[Long].
An extension method was tried, but could not be fully constructed:
Playground.Price.+(price1.usd)
failed with:
Found: (price1.usd : Option[Long])
Required: Playground.Price
Expectation
This should have resolved the + on Option[Long]. The following works for example:
object options:
extension (long1: Option[Long])
def +(long2: Option[Long]): Option[Long] = (long1, long2) match
case (Some(long1), Some(long2)) => Some(long1 + long2)
case (Some(long1), None) => Some(long1)
case (None, Some(long2)) => Some(long2)
case (None, None) => None
case class Price(usd: Option[Long] = None)
object Price:
extension (price1: Price)
def +(price2: Price): Price = Price(usd = options.+(price1.usd)(price2.usd))https://scastie.scala-lang.org/NyjdElF5SCaqZCSQLDnJNg
Thanks