Skip to content

Pain point using -Yexplicit-nulls with Regex unapply #14672

Open
@griggt

Description

@griggt

Compiler version

3.2.0-RC1-bin-20220308-29073f1-NIGHTLY with -Yexplicit-nulls

Minimized code

scala> val Split = "([^#]+)?(?:#(.+)?)?".r
val Split: scala.util.matching.Regex = ([^#]+)?(?:#(.+)?)?

scala> "#foo" match 
     |   case Split(pre, _) if pre != null => println(s"pre=$pre")
     |   case _ => println("no match")
     | 
-- Error: ----------------------------------------------------------------------
2 |  case Split(pre, _) if pre != null => println(s"pre=$pre")
  |                        ^^^^^^^^^^^
  |          Values of types String and Null cannot be compared with == or !=
1 error found

but removing the guard gives:

scala> "#foo" match 
     |   case Split(pre, _) => println(s"pre=$pre")
     |   case _ => println("no match")
     | 
pre=null

Output

As shown above

Expectation

pre is typed as String | Null

Notes

I suspect this is due to #7871?

Is there anything I can do here besides locally importing language.unsafeNulls?

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions