-
Notifications
You must be signed in to change notification settings - Fork 1.1k
java.lang.NullPointerException on pattern match in dotty REPL #4051
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thanks for the report. That’s a crash in the compiler, those are always bugs. Dotty from homebrew is likely the latest release. Todo: recheck on latest master. |
Can be reproduced with |
There is no error with an explicit scala> val id = new PartialFunction[Int, Int] {
def apply(x: Int) = x
def isDefinedAt(x: Int) = true
}
val id: PartialFunction[Int, Int] = <function1>
scala> Seq(1, 2, 3).collect(id)
val res1: Seq[Int] = List(1, 2, 3) But even an identity function fails: scala> def id(x: Int) = x
def id(x: Int): Int
scala> Seq(1, 2, 3).collect(id)
Exception in thread "main" java.lang.NullPointerException
at dotty.tools.dotc.transform.ExpandPrivate.ensurePrivateAccessible(ExpandPrivate.scala:93)
... |
@allanrenucci is the |
By quickly looking at it, I would say |
Here is the reason
I see two options. A hack to fix this is to just create a final def sourceFile(implicit ctx: Context): AbstractFile = {
val file = associatedFile
if (file != null && !file.path.endsWith("class")) file
else {
val topLevelCls = denot.topLevelClass(ctx.withPhaseNoLater(ctx.flattenPhase))
topLevelCls.getAnnotation(defn.SourceFileAnnot) match {
case Some(sourceAnnot) => sourceAnnot.argumentConstant(0) match {
case Some(Constant(path: String)) => // Changes here:
val plainFile = AbstractFile.getFile(path)
if (plainFile != null) plainFile
else new dotty.tools.io.VirtualFile(path)
case none => null
}
case none => null
}
}
} This solves the error and produces no errors in object SourceTree {
def fromSymbol(sym: ClassSymbol, id: String = "")(implicit ctx: Context): Option[SourceTree] = {
if (sym == defn.SourceFileAnnot || // FIXME: No SourceFile annotation on SourceFile itself
sym.sourceFile == null) // FIXME: We cannot deal with external projects yet
None
... The second option would be to decide that the anonymous class which becomes a PartialFunction object should have |
I don't think |
Might be more of stackoverflow question not a issues at all but I was playing with dotty REPL with a tuple2 and
_._2
works fineBut when I pattern match and get the second column it throws a
NullPointerException
.Get the same error with
Seq(("Porcupine", 1), ("Floyd", 2), ("Phil Collins", 3)).collect {case x => x._2}
.Tried a bit exploring the reason which is in
ExpandPrivate#ensurePrivateAccessible
which is lineassert(d.symbol.sourceFile != null && isSimilar(d.symbol.sourceFile.path, ctx.owner.sourceFile.path)
I also tried with simpler pattern match, it does not work.
Don't know what is
SymDenotation.symbol
orContext.owner
. I installed dotty using homebrew and believe it is the built from latest codebase.The text was updated successfully, but these errors were encountered: