You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The following compiles as expected without -Yexplicit-nulls, but with -Yexplicit-nulls specified produces an at best unhelpful error message,
importscala.util.matching.RegexobjectTestextendsApp {
defhead(s: String, r: Regex):Option[(String, String)] =
s.trim match {
case r(hd, tl) =>Some((hd, tl))
case _ =>None
}
}
sbt:dotty> dotc -Yexplicit-nulls -d local/classes local/nulls.scala
[warn] Multiple main classes detected. Run 'show discoveredMainClasses' to see the list
[info] Running (fork) dotty.tools.dotc.Main -classpath /home/miles/.ivy2/cache/org.scala-lang/scala-library/jars/scala-library-2.13.1.jar:/home/miles/projects/dotty/library/../out/bootstrap/dotty-library-bootstrapped/scala-0.22/dotty-library_0.22-0.22.0-bin-SNAPSHOT.jar -Yexplicit-nulls -d local/classes local/nulls.scala
-- [E127] Syntax Error: local/nulls.scala:6:11 ---------------------------------
6 | case r(hd, tl) => Some((hd, tl))
| ^
|r cannot be used as an extractor in a pattern because it lacks an unapply or unapplySeq method
longer explanation available when compiling with `-explain`
-- [E006] Unbound Identifier Error: local/nulls.scala:6:30 ---------------------
6 | case r(hd, tl) => Some((hd, tl))
| ^^
| Not found: hd
longer explanation available when compiling with `-explain`
-- [E006] Unbound Identifier Error: local/nulls.scala:6:34 ---------------------
6 | case r(hd, tl) => Some((hd, tl))
| ^^
| Not found: tl
longer explanation available when compiling with `-explain`
3 errors found
milessabin
changed the title
Unhelpful error message with -Yexplicit-nulls or unhelpful typing of String#trim
Unhelpful error message with -Yexplicit-nulls or unhelpful typing of String#trim
Dec 31, 2019
Maybe something as simple as changing the error to value r of type (String|Null) cannot be used as an extractor in a pattern because it lacks an unapply or unapplySeq method would suffice?
The following compiles as expected without
-Yexplicit-nulls
, but with-Yexplicit-nulls
specified produces an at best unhelpful error message,Desugaring the match a bit to,
shows that the issue is the result type of
String#trim
,A workaround is to explicitly test the result of
s.trim
againstnull
,The text was updated successfully, but these errors were encountered: