Unexpected NullPointerException When Using Scala's Option with Custom Implicits in 2.13.6
After trying multiple solutions online, I still can't figure this out... I'm working on a project and hit a roadblock... I'm working with a `NullPointerException` in my Scala application when trying to use `Option` with some custom implicits I've defined. Here's a simplified version of what I'm trying to achieve: ```scala case class User(id: Int, name: String) object UserUtils { implicit class UserOption(userOpt: Option[User]) { def greet: String = userOpt.map(u => s"Hello, ${u.name}!").getOrElse("User not found") } } val user: Option[User] = None println(user.greet) // This throws NullPointerException ``` The intention here is to create a method `greet` that operates on an `Option[User]` and either greets the user or returns a default message if the user is not present. However, when I try to call `greet` on an `Option` that is `None`, I end up with a `NullPointerException` instead of the expected "User not found" message. I've made sure to wrap my `greet` method in an implicit class to extend the functionality, but for some reason, it seems like when the `userOpt` is `None`, the code is somehow trying to access a null value. I've also checked that the `User` class is not inadvertently causing any issues. I've tried adding some debug print statements, and it seems that the `userOpt` is indeed `None` at the point of calling `greet`. I've verified other parts of my code to ensure that the `Option` is being handled correctly, so this behavior feels quite unexpected to me. Has anyone encountered this scenario or can shed some light on why this might be happening? Is there something I'm missing with how implicits are resolved in this context? Any insights would be appreciated! I'd really appreciate any guidance on this. My development environment is Linux. Has anyone else encountered this?