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

error typed tree leaves the typer phase unreported after failed implicit view application: NPE in MixinTransformer #8583

Closed
scabug opened this Issue May 13, 2014 · 5 comments

Comments

Projects
None yet
4 participants
@scabug
Copy link

scabug commented May 13, 2014

Compiling the following code:

class Test {

  case class A( value: Double ) {
    def *( o: A ) = A( value * o.value )
  }

  implicit def doubleToA( d: Double ) = A( d )
  implicit def listToA( in: List[A] ): A = in.head

  val result: A = List( A( 1 ) ) map { 2.0 * _ } //this line causes the compiler to crash
}

Stacktrace:

error: java.lang.NullPointerException
        at scala.tools.nsc.transform.Mixin$MixinTransformer.scala$tools$nsc$transform$Mixin$MixinTransformer$$postTransform(Mixin.scala:1132)
        at scala.tools.nsc.transform.Mixin$MixinTransformer$$anonfun$transform$1.apply(Mixin.scala:1239)
        at scala.tools.nsc.transform.Mixin$MixinTransformer$$anonfun$transform$1.apply(Mixin.scala:1239)
        at scala.reflect.internal.SymbolTable.enteringPhase(SymbolTable.scala:242)
        at scala.reflect.internal.SymbolTable.exitingPhase(SymbolTable.scala:263)
        at scala.tools.nsc.transform.Mixin$MixinTransformer.transform(Mixin.scala:1239)
        at scala.tools.nsc.transform.Mixin$MixinTransformer.transform(Mixin.scala:468)
        at scala.reflect.internal.Trees$class.itransform(Trees.scala:1340)
        at scala.reflect.internal.SymbolTable.itransform(SymbolTable.scala:16)
        at scala.reflect.internal.SymbolTable.itransform(SymbolTable.scala:16)
        at scala.reflect.api.Trees$Transformer.transform(Trees.scala:2555)
        at scala.tools.nsc.transform.Mixin$MixinTransformer.transform(Mixin.scala:1236)
        at scala.tools.nsc.transform.Mixin$MixinTransformer.transform(Mixin.scala:468)
        at scala.reflect.internal.Trees$$anonfun$itransform$2.apply(Trees.scala:1356)
        at scala.reflect.internal.Trees$$anonfun$itransform$2.apply(Trees.scala:1354)
        at scala.reflect.api.Trees$Transformer.atOwner(Trees.scala:2600)
        at scala.reflect.internal.Trees$class.itransform(Trees.scala:1353)
        at scala.reflect.internal.SymbolTable.itransform(SymbolTable.scala:16)
        at scala.reflect.internal.SymbolTable.itransform(SymbolTable.scala:16)
        at scala.reflect.api.Trees$Transformer.transform(Trees.scala:2555)
        at scala.tools.nsc.transform.Mixin$MixinTransformer.transform(Mixin.scala:1236)
        at scala.tools.nsc.transform.Mixin$MixinTransformer.transform(Mixin.scala:468)
        at scala.reflect.api.Trees$Transformer$$anonfun$transformStats$1.apply(Trees.scala:2589)
        at scala.reflect.api.Trees$Transformer$$anonfun$transformStats$1.apply(Trees.scala:2587)
        at scala.collection.immutable.List.loop$1(List.scala:172)
        at scala.collection.immutable.List.mapConserve(List.scala:188)
        at scala.reflect.api.Trees$Transformer.transformStats(Trees.scala:2587)
        at scala.reflect.internal.Trees$class.itransform(Trees.scala:1397)
        at scala.reflect.internal.SymbolTable.itransform(SymbolTable.scala:16)
        at scala.reflect.internal.SymbolTable.itransform(SymbolTable.scala:16)
        at scala.reflect.api.Trees$Transformer.transform(Trees.scala:2555)
        at scala.tools.nsc.transform.Mixin$MixinTransformer.transform(Mixin.scala:1236)
        at scala.tools.nsc.transform.Mixin$MixinTransformer.transform(Mixin.scala:468)
        at scala.reflect.api.Trees$Transformer.transformTemplate(Trees.scala:2563)
        at scala.reflect.internal.Trees$$anonfun$itransform$4.apply(Trees.scala:1401)
        at scala.reflect.internal.Trees$$anonfun$itransform$4.apply(Trees.scala:1400)
        at scala.reflect.api.Trees$Transformer.atOwner(Trees.scala:2600)
        at scala.reflect.internal.Trees$class.itransform(Trees.scala:1399)
        at scala.reflect.internal.SymbolTable.itransform(SymbolTable.scala:16)
        at scala.reflect.internal.SymbolTable.itransform(SymbolTable.scala:16)
        at scala.reflect.api.Trees$Transformer.transform(Trees.scala:2555)
        at scala.tools.nsc.transform.Mixin$MixinTransformer.transform(Mixin.scala:1236)
        at scala.tools.nsc.transform.Mixin$MixinTransformer.transform(Mixin.scala:468)
        at scala.reflect.api.Trees$Transformer$$anonfun$transformStats$1.apply(Trees.scala:2589)
        at scala.reflect.api.Trees$Transformer$$anonfun$transformStats$1.apply(Trees.scala:2587)
        at scala.collection.immutable.List.loop$1(List.scala:172)
        at scala.collection.immutable.List.mapConserve(List.scala:188)
        at scala.reflect.api.Trees$Transformer.transformStats(Trees.scala:2587)
        at scala.reflect.internal.Trees$$anonfun$itransform$7.apply(Trees.scala:1419)
        at scala.reflect.internal.Trees$$anonfun$itransform$7.apply(Trees.scala:1419)
        at scala.reflect.api.Trees$Transformer.atOwner(Trees.scala:2600)
        at scala.reflect.internal.Trees$class.itransform(Trees.scala:1418)
        at scala.reflect.internal.SymbolTable.itransform(SymbolTable.scala:16)
        at scala.reflect.internal.SymbolTable.itransform(SymbolTable.scala:16)
        at scala.reflect.api.Trees$Transformer.transform(Trees.scala:2555)
        at scala.tools.nsc.transform.Mixin$MixinTransformer.transform(Mixin.scala:1236)
        at scala.tools.nsc.transform.Mixin$MixinTransformer.transform(Mixin.scala:468)
        at scala.tools.nsc.ast.Trees$Transformer.transformUnit(Trees.scala:147)
        at scala.tools.nsc.transform.Transform$Phase.apply(Transform.scala:30)
        at scala.tools.nsc.Global$GlobalPhase.applyPhase(Global.scala:430)
        at scala.tools.nsc.Global$GlobalPhase$$anonfun$run$1.apply(Global.scala:397)
        at scala.tools.nsc.Global$GlobalPhase$$anonfun$run$1.apply(Global.scala:397)
        at scala.collection.Iterator$class.foreach(Iterator.scala:743)
        at scala.collection.AbstractIterator.foreach(Iterator.scala:1174)
        at scala.tools.nsc.Global$GlobalPhase.run(Global.scala:397)
        at scala.tools.nsc.Global$Run.compileUnitsInternal(Global.scala:1625)
        at scala.tools.nsc.Global$Run.compileUnits(Global.scala:1610)
        at scala.tools.nsc.Global$Run.compileSources(Global.scala:1605)
        at scala.tools.nsc.Global$Run.compile(Global.scala:1703)
        at scala.tools.nsc.Driver.doCompile(Driver.scala:34)
        at scala.tools.nsc.MainClass.doCompile(Main.scala:23)
        at scala.tools.nsc.Driver.process(Driver.scala:55)
        at scala.tools.nsc.Driver.main(Driver.scala:68)
        at scala.tools.nsc.Main.main(Main.scala)
@scabug

This comment has been minimized.

Copy link

scabug commented May 13, 2014

Imported From: https://issues.scala-lang.org/browse/SI-8583?orig=1
Reporter: Martin Großmann (mgrossmann)
Affected Versions: 2.11.0

@scabug

This comment has been minimized.

Copy link

scabug commented May 13, 2014

@retronym said:
Here's the sneaky unreported error the gets out of the typechecker:

 qbin/scalac -Xprint:typer sandbox/test.scala [[syntax trees at end of                     typer]] // test.scala
package <empty> {
  class Test extends scala.AnyRef {
    def <init>(): Test = {
      Test.super.<init>();
      ()
    };
    abstract trait A extends scala.AnyRef {
      def *(o: Test.this.A): Test.this.A
    };
    implicit def doubleToA(d: Double): Test.this.A = scala.this.Predef.???;
    implicit def listToA(in: List[Test.this.A]): Test.this.A = scala.this.Predef.???;
    def as: List[Test.this.A] = scala.this.Predef.???;
    private[this] val result: Test.this.A = Test.this.listToA(Test.this.as.map[Nothing, List[Nothing]](((x: Test.this.A) => 2.0.<$times: error>(x)))(immutable.this.List.canBuildFrom[Nothing]));
    <stable> <accessor> def result: Test.this.A = Test.this.result
  }
}
@scabug

This comment has been minimized.

Copy link

scabug commented May 13, 2014

@retronym said:
BTW, thanks for the tiny minimization!

@scabug

This comment has been minimized.

Copy link

scabug commented May 13, 2014

Martin Großmann (mgrossmann) said:
You're welcome. We already had to isolate the problem to find a workaround. From there on it was only a bit of try and error and getting rid of all dependencies.

@diesalbla

This comment has been minimized.

Copy link

diesalbla commented Nov 16, 2018

I have tested this bug in the 2.13.x version, and it has already been fixed.

I have also tested it in the 2.12.6 version, by opening the Scala console and pasting it. Curiously, in that version the compiler still crashes, but with a MatchError error instead of an NPE.

warning: an unexpected type representation reached the compiler backend while compiling <console>: <error>. If possible, please file a bug on https://github.com/scala/bug/issues.
scala.MatchError: <error> (of class scala.reflect.internal.Types$ErrorType$)
	at scala.tools.nsc.backend.jvm.BTypesFromSymbols.typeToBType(BTypesFromSymbols.scala:186)
	at scala.tools.nsc.backend.jvm.BTypesFromSymbols.methodBTypeFromMethodType(BTypesFromSymbols.scala:127)
	at scala.tools.nsc.backend.jvm.BTypesFromSymbols.methodBTypeFromSymbol(BTypesFromSymbols.scala:118)
	at scala.tools.nsc.backend.jvm.BTypesFromSymbols.$anonfun$buildInlineInfoFromClassSymbol$6(BTypesFromSymbols.scala:580)

The same error is still present on the milestone version 2.13.0-M1, but the bug is already fixed at v2.13.0-M4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment