Skip to content
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

compiler NPE in pattern matcher #8337

Closed
scabug opened this issue Feb 25, 2014 · 10 comments
Closed

compiler NPE in pattern matcher #8337

scabug opened this issue Feb 25, 2014 · 10 comments
Assignees
Labels

Comments

@scabug
Copy link

scabug commented Feb 25, 2014

Ran into a compiler crash today. Fails on 2.10.3 (and .4-RC2) as well. Not minimized, but easy to to reproduce.

Check out  @91f434b from https://github.com/mighdoll/sparkle.
cd sparkle
sbt/sbt
> test

Remove the line tagged 'COMPILER bug' and the problem goes away.
Partial tack trace:

java.lang.NullPointerException
	at scala.tools.nsc.transform.patmat.MatchTranslation$MatchTranslator$class.translateMatch(MatchTranslation.scala:134)
	at scala.tools.nsc.transform.patmat.PatternMatching$OptimizingMatchTranslator.translateMatch(PatternMatching.scala:87)
	at scala.tools.nsc.transform.patmat.PatternMatching$MatchTransformer.transform(PatternMatching.scala:60)
	at scala.tools.nsc.transform.patmat.PatternMatching$MatchTransformer.transform(PatternMatching.scala:55)
	at scala.reflect.internal.Trees$$anonfun$itransform$3.apply(Trees.scala:1251)
	at scala.reflect.internal.Trees$$anonfun$itransform$3.apply(Trees.scala:1251)
	at scala.reflect.api.Trees$Transformer.atOwner(Trees.scala:2936)
	at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.atOwner(TypingTransformers.scala:34)
	at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.atOwner(TypingTransformers.scala:28)
	at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.atOwner(TypingTransformers.scala:19)
	at scala.reflect.internal.Trees$class.itransform(Trees.scala:1250)
	at scala.reflect.internal.SymbolTable.itransform(SymbolTable.scala:13)
	at scala.reflect.internal.SymbolTable.itransform(SymbolTable.scala:13)
	at scala.reflect.api.Trees$Transformer.transform(Trees.scala:2897)
	at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.transform(TypingTransformers.scala:48)
	at scala.tools.nsc.transform.patmat.PatternMatching$MatchTransformer.transform(PatternMatching.scala:71)
	at scala.tools.nsc.transform.patmat.PatternMatching$MatchTransformer.transform(PatternMatching.scala:55)
	at scala.reflect.api.Trees$Transformer$$anonfun$transformTrees$1.apply(Trees.scala:2900)
	at scala.reflect.api.Trees$Transformer$$anonfun$transformTrees$1.apply(Trees.scala:2900)
	at scala.collection.immutable.List.loop$1(List.scala:170)
	at scala.collection.immutable.List.mapConserve(List.scala:186)
	at scala.reflect.api.Trees$Transformer.transformTrees(Trees.scala:2900)
	at scala.reflect.internal.Trees$class.itransform(Trees.scala:1219)
	at scala.reflect.internal.SymbolTable.itransform(SymbolTable.scala:13)
	at scala.reflect.internal.SymbolTable.itransform(SymbolTable.scala:13)
	at scala.reflect.api.Trees$Transformer.transform(Trees.scala:2897)
@scabug
Copy link
Author

scabug commented Feb 25, 2014

Imported From: https://issues.scala-lang.org/browse/SI-8337?orig=1
Reporter: Lee Mighdoll (mighdoll)
Affected Versions: 2.10.4-RC3
See #7291, #7319

@scabug
Copy link
Author

scabug commented Mar 18, 2014

@gkossakowski said:
Assigning to myself for now. I've spent some time minimizing it already.

@scabug
Copy link
Author

scabug commented Mar 18, 2014

@gkossakowski said:
Notes to myself:

  • the crash is in TestV1Api.scala
  • the crash in patmat is not a bug in patmat, it tries to work with error trees that came from typer
  • in the code, there's a call to arbitraryColumn method:
    def arbitraryColumn[T: TypeTag: Ordering, U: TypeTag](prefix: String, storage: WriteableRamStore)(implicit execution: ExecutionContext): Gen[Seq[Event[T, U]]]
    as you can see, the type parameters T and U are not bound by anything. The method signature appears to be missing something.
  • strangely enough we infer T = Long, U = Nothing. With no constraints, I'd expect both T and U to be Nothing
  • annotating the call so it comes arbitraryColumn[Long, Nothing](...) makes the crash disappear
  • separate compilation makes the crash disappear in all circumstances

@scabug
Copy link
Author

scabug commented Mar 21, 2014

@retronym said:

% scalac-hash v2.10.2~49 @args.txt
/Users/jason/code/sparkle/src/test/scala/nest/sparkle/time/protocol/TestV1Api.scala:111: error: diverging implicit expansion for type Ordering[T]
starting with method Tuple9 in object Ordering
    val x = arbitraryColumn("V1Protocol.domainRange", testDb)   // COMPILER bug, remove this to fix
                           ^
one error found

% scalac-hash v2.10.2~48 @args.txt
/Users/jason/code/sparkle/src/test/scala/nest/sparkle/time/protocol/TestV1Api.scala:116: error: erroneous or inaccessible type
      data.foreach { datum =>
                           ^
/Users/jason/code/sparkle/src/test/scala/nest/sparkle/time/transform/TestDomainRange.scala:31: error: erroneous or inaccessible type
  def minMaxEvents(events: Seq[Event[Long, Double]]): (Long, Long, Double, Double) = {
                                                                                     ^
/Users/jason/code/sparkle/src/test/scala/nest/sparkle/util/Repeating.scala:21: error: erroneous or inaccessible type
  def repeatWithDelay[T](maxAttempts: Int, delayMsec: Int = 100)(fn: => Option[T]): Option[T] = {
                                                                                                ^
/Users/jason/code/sparkle/src/test/scala/nest/sparkle/util/TestObservableFuture.scala:42: error: erroneous or inaccessible type
  test("future string to observable string") {
                                             ^
/Users/jason/code/sparkle/src/test/scala/nest/sparkle/util/TestPeekIterator.scala:27: error: erroneous or inaccessible type
    peeked(list).toList shouldEqual list
                        ^
5 errors found

% tail -n 20 args.txt
-language:postfixOps
/Users/jason/code/sparkle/src/test/scala/nest/sparkle/graph/TestTemplate.scala
/Users/jason/code/sparkle/src/test/scala/nest/sparkle/legacy/DirectoryRegistryFixture.scala
/Users/jason/code/sparkle/src/test/scala/nest/sparkle/legacy/SampleData.scala
/Users/jason/code/sparkle/src/test/scala/nest/sparkle/legacy/TestCsvLoad.scala
/Users/jason/code/sparkle/src/test/scala/nest/sparkle/legacy/TestCustomApi.scala
/Users/jason/code/sparkle/src/test/scala/nest/sparkle/legacy/TestDataRestApi.scala
/Users/jason/code/sparkle/src/test/scala/nest/sparkle/legacy/TestDataSet.scala
/Users/jason/code/sparkle/src/test/scala/nest/sparkle/legacy/TestDeepDirectoryRegistry.scala
/Users/jason/code/sparkle/src/test/scala/nest/sparkle/legacy/TestDirectoryBasic.scala
/Users/jason/code/sparkle/src/test/scala/nest/sparkle/legacy/TestDirectoryRegistry.scala
/Users/jason/code/sparkle/src/test/scala/nest/sparkle/legacy/TestHttpServer.scala
/Users/jason/code/sparkle/src/test/scala/nest/sparkle/legacy/TestTsvLoad.scala
/Users/jason/code/sparkle/src/test/scala/nest/sparkle/loader/TestTextTableParser.scala
/Users/jason/code/sparkle/src/test/scala/nest/sparkle/time/protocol/ArbitraryColumn.scala
/Users/jason/code/sparkle/src/test/scala/nest/sparkle/time/protocol/TestV1Api.scala
/Users/jason/code/sparkle/src/test/scala/nest/sparkle/time/transform/TestDomainRange.scala
/Users/jason/code/sparkle/src/test/scala/nest/sparkle/util/Repeating.scala
/Users/jason/code/sparkle/src/test/scala/nest/sparkle/util/TestObservableFuture.scala
/Users/jason/code/sparkle/src/test/scala/nest/sparkle/util/TestPeekIterator.scala

% (cd scala; git show v2.10.2~48)
/code/scala
commit 2ecd09fe1d79371ea5bcc529066d7bda0146cca3
Merge: 14c5027 ef04619
Author: Paul Phillips <paulp@improving.org>
Date:   Fri Apr 19 14:28:07 2013 -0700

    Merge pull request #2370 from retronym/ticket/7319-2

    SI-7319 Avoid unflushed error/warning buffers in startContext

@scabug
Copy link
Author

scabug commented Mar 21, 2014

@retronym said:
Relates to #7319

@scabug
Copy link
Author

scabug commented Mar 21, 2014

@gkossakowski said:
What all those errors mean?

@scabug
Copy link
Author

scabug commented Mar 21, 2014

@retronym said (edited on Mar 21, 2014 4:05:51 PM UTC):
That means the ErrorType which should have been reported in the typer phase is detected and reported as a generic error in pickler phase. Probably the difference is that I compiled a subset of files that didn't trip failure in the patmat phase.

@scabug
Copy link
Author

scabug commented Mar 21, 2014

@retronym said (edited on Mar 21, 2014 4:56:00 PM UTC):
I minimized that down to:

abstract class InaccessibleType {
  def foo[T, U](implicit ev: Ordering[T])
  def convertTo[T: Ordering]: T = ???

  foo[Long, Double]
  foo
  convertTo[String] // erroneous or inaccessible type
}

Scala 2.11 exhibits the same failure from v2.11.0-M2-256-g3f21f00 (the relevent merge from 2.10.x to master that I found using git what-branch --reference master ef04619.), until this fix from @hubertp restored reporting of the diverging implicit error: scala/scala#2428

That fix turned out to be so vital, that it was backported to 2.10.x under a forward compatibility flag: dotta/scala@fdead2b

scalac-hash v2.10.3 -Xdivergence211 sandbox/test.scala
sandbox/test.scala:7: error: ambiguous implicit values:
 both method Tuple9 in object Ordering of type [T1, T2, T3, T4, T5, T6, T7, T8, T9](implicit ord1: scala.math.Ordering[T1], implicit ord2: scala.math.Ordering[T2], implicit ord3: scala.math.Ordering[T3], implicit ord4: scala.math.Ordering[T4], implicit ord5: scala.math.Ordering[T5], implicit ord6: scala.math.Ordering[T6], implicit ord7: scala.math.Ordering[T7], implicit ord8: scala.math.Ordering[T8], implicit ord9: scala.math.Ordering[T9])scala.math.Ordering[(T1, T2, T3, T4, T5, T6, T7, T8, T9)]
 and object Long in object Ordering of type scala.math.Ordering.Long.type
 match expected type Ordering[T]
  foo
  ^
one error found

So I think we can use that flag as a workaround for sparkle, and see what other problems arise (ie, why are there ambiguous/diverging implicits now?). It would also be prudent to submit that minimization as a test case to lock down the progression.

@scabug
Copy link
Author

scabug commented Mar 21, 2014

Lee Mighdoll (mighdoll) said:
Thanks for minimizing. Just to clarify, in this case my only goal was to help identify a compiler crash. So feel free to skip doing any extra work in the workaround direction.

@scabug
Copy link
Author

scabug commented Jan 29, 2016

@retronym said:
I can't reproduce this anymore on 2.11 using my minimization above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants