Skip to content

scalac FatalError: unexpected UnApply c.universe.Select.unapply(<<unapply-selector>: error>) <unapply> (c.universe.NewTag.unapply(<unapply-selector>) <unapply> (c.universe.New.unapply(<unapply-selector>) <unapply> ((tpt @ _))), (initName @ _)) #10011

Closed
@scabug

Description

@scabug

Scalac 2.12 got a fatal error compiling the following code snippet.

It seems to be a recent regression. The case is generated from an exsiting test program in the scala repository.

$ scalac -version
Scala compiler version 2.12.0-20161028-204919-0666377 -- Copyright 2002-2016, LAMP/EPFL and Lightbend, Inc.



$ scalac abc.scala
abc.scala:4: error: not found: type Utils
    object utils extends Utils { val context: c.type = c }
                         ^
error: unexpected UnApply c.universe.Select.unapply(<<unapply-selector>: error>) <unapply> (c.universe.NewTag.unapply(<unapply-selector>) <unapply> (c.universe.New.unapply(<unapply-selector>) <unapply> ((tpt @ _))), (initName @ _))
error: scala.reflect.internal.FatalError: unexpected UnApply c.universe.Select.unapply(<<unapply-selector>: error>) <unapply> (c.universe.NewTag.unapply(<unapply-selector>) <unapply> (c.universe.New.unapply(<unapply-selector>) <unapply> ((tpt @ _))), (initName @ _))
	at scala.reflect.internal.Reporting.abort(Reporting.scala:61)
	at scala.reflect.internal.Reporting.abort$(Reporting.scala:57)
	at scala.reflect.internal.SymbolTable.abort(SymbolTable.scala:16)
	at scala.tools.nsc.typechecker.Typers$Typer.typedInAnyMode$1(Typers.scala:5457)
	at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:5469)
	at scala.tools.nsc.typechecker.Typers$Typer.runTyper$1(Typers.scala:5505)
	at scala.tools.nsc.typechecker.Typers$Typer.typedInternal(Typers.scala:5535)
	at scala.tools.nsc.typechecker.Typers$Typer.body$2(Typers.scala:5479)
	at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5483)
	at scala.tools.nsc.typechecker.Typers$Typer.$anonfun$typedArg$1(Typers.scala:3205)
	at scala.tools.nsc.typechecker.Typers$Typer.withCondConstrTyper(Typers.scala:481)
	at scala.tools.nsc.typechecker.Typers$Typer.typedArg(Typers.scala:3205)
	at scala.tools.nsc.typechecker.PatternTypers$PatternTyper.typedArgWithFormal$1(PatternTypers.scala:113)
	at scala.tools.nsc.typechecker.PatternTypers$PatternTyper.$anonfun$typedArgsForFormals$1(PatternTypers.scala:116)
	at scala.runtime.Tuple2Zipped$.$anonfun$map$1(Tuple2Zipped.scala:47)
	at scala.collection.immutable.List.foreach(List.scala:378)
	at scala.runtime.Tuple2Zipped$.map$extension(Tuple2Zipped.scala:45)
	at scala.tools.nsc.typechecker.PatternTypers$PatternTyper.typedArgsForFormals(PatternTypers.scala:116)
	at scala.tools.nsc.typechecker.PatternTypers$PatternTyper.typedArgsForFormals$(PatternTypers.scala:110)
	at scala.tools.nsc.typechecker.Typers$Typer.typedArgsForFormals(Typers.scala:111)
	at scala.tools.nsc.typechecker.PatternTypers$PatternTyper.makeTypedUnapply$1(PatternTypers.scala:314)
	at scala.tools.nsc.typechecker.PatternTypers$PatternTyper.doTypedUnapply(PatternTypers.scala:329)
	at scala.tools.nsc.typechecker.PatternTypers$PatternTyper.doTypedUnapply$(PatternTypers.scala:263)
	at scala.tools.nsc.typechecker.Typers$Typer.doTypedUnapply(Typers.scala:111)
	at scala.tools.nsc.typechecker.PatternTypers$PatternTyper.wrapClassTagUnapply(PatternTypers.scala:342)
	at scala.tools.nsc.typechecker.PatternTypers$PatternTyper.wrapClassTagUnapply$(PatternTypers.scala:332)
	at scala.tools.nsc.typechecker.Typers$Typer.wrapClassTagUnapply(Typers.scala:111)
	at scala.tools.nsc.typechecker.PatternTypers$PatternTyper.makeTypedUnapply$1(PatternTypers.scala:318)
	at scala.tools.nsc.typechecker.PatternTypers$PatternTyper.doTypedUnapply(PatternTypers.scala:329)
	at scala.tools.nsc.typechecker.PatternTypers$PatternTyper.doTypedUnapply$(PatternTypers.scala:263)
	at scala.tools.nsc.typechecker.Typers$Typer.doTypedUnapply(Typers.scala:111)
	at scala.tools.nsc.typechecker.Typers$Typer.doTypedApply(Typers.scala:3627)
	at scala.tools.nsc.typechecker.Typers$Typer.normalTypedApply$1(Typers.scala:4652)
	at scala.tools.nsc.typechecker.Typers$Typer.typedApply$1(Typers.scala:4686)
	at scala.tools.nsc.typechecker.Typers$Typer.typedInAnyMode$1(Typers.scala:5452)
	at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:5469)
	at scala.tools.nsc.typechecker.Typers$Typer.runTyper$1(Typers.scala:5505)
	at scala.tools.nsc.typechecker.Typers$Typer.typedInternal(Typers.scala:5535)
	at scala.tools.nsc.typechecker.Typers$Typer.body$2(Typers.scala:5479)
	at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5483)
	at scala.tools.nsc.typechecker.Typers$Typer.$anonfun$typed1$31(Typers.scala:4657)
	at scala.collection.immutable.List.foreach(List.scala:378)
	at scala.tools.nsc.typechecker.Typers$Typer.$anonfun$typed1$28(Typers.scala:4657)
	at scala.tools.nsc.typechecker.Typers$Typer.onError$3(Typers.scala:4628)
	at scala.tools.nsc.typechecker.Typers$Typer.normalTypedApply$1(Typers.scala:4654)
	at scala.tools.nsc.typechecker.Typers$Typer.typedApply$1(Typers.scala:4686)
	at scala.tools.nsc.typechecker.Typers$Typer.typedInAnyMode$1(Typers.scala:5452)
	at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:5469)
	at scala.tools.nsc.typechecker.Typers$Typer.runTyper$1(Typers.scala:5505)
	at scala.tools.nsc.typechecker.Typers$Typer.typedInternal(Typers.scala:5535)
	at scala.tools.nsc.typechecker.Typers$Typer.body$2(Typers.scala:5479)
	at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5483)
	at scala.tools.nsc.typechecker.Typers$Typer.$anonfun$typedPattern$2(Typers.scala:5621)
	at scala.tools.nsc.typechecker.Contexts$Context.withMode(Contexts.scala:383)
	at scala.tools.nsc.typechecker.Contexts$Context.withImplicitsDisabledAllowEnrichment(Contexts.scala:389)
	at scala.tools.nsc.typechecker.Typers$Typer.$anonfun$typedPattern$1(Typers.scala:5621)
	at scala.tools.nsc.typechecker.TypeDiagnostics.typingInPattern(TypeDiagnostics.scala:62)
	at scala.tools.nsc.typechecker.TypeDiagnostics.typingInPattern$(TypeDiagnostics.scala:59)
	at scala.tools.nsc.Global$$anon$1.typingInPattern(Global.scala:424)
	at scala.tools.nsc.typechecker.Typers$Typer.typedPattern(Typers.scala:5621)
	at scala.tools.nsc.typechecker.Typers$Typer.typedCase(Typers.scala:2486)
	at scala.tools.nsc.typechecker.Typers$Typer.$anonfun$typedCases$1(Typers.scala:2526)
	at scala.collection.immutable.List.loop$1(List.scala:173)
	at scala.collection.immutable.List.mapConserve(List.scala:189)
	at scala.tools.nsc.typechecker.Typers$Typer.typedCases(Typers.scala:2525)
	at scala.tools.nsc.typechecker.Typers$Typer.typedMatch(Typers.scala:2537)
	at scala.tools.nsc.typechecker.Typers$Typer.typedVirtualizedMatch$1(Typers.scala:4402)
	at scala.tools.nsc.typechecker.Typers$Typer.typedOutsidePatternMode$1(Typers.scala:5431)
	at scala.tools.nsc.typechecker.Typers$Typer.typedInAnyMode$1(Typers.scala:5462)
	at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:5469)
	at scala.tools.nsc.typechecker.Typers$Typer.runTyper$1(Typers.scala:5505)
	at scala.tools.nsc.typechecker.Typers$Typer.typedInternal(Typers.scala:5535)
	at scala.tools.nsc.typechecker.Typers$Typer.body$2(Typers.scala:5479)
	at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5483)
	at scala.tools.nsc.typechecker.Typers$Typer.$anonfun$typedArg$1(Typers.scala:3205)
	at scala.tools.nsc.typechecker.Typers$Typer.withCondConstrTyper(Typers.scala:481)
	at scala.tools.nsc.typechecker.Typers$Typer.typedArg(Typers.scala:3205)
	at scala.tools.nsc.typechecker.Typers$Typer.$anonfun$typedArgs$1(Typers.scala:3210)
	at scala.collection.immutable.List.loop$1(List.scala:173)
	at scala.collection.immutable.List.mapConserve(List.scala:189)
	at scala.tools.nsc.typechecker.Typers$Typer.typedArgs(Typers.scala:3210)
	at scala.tools.nsc.typechecker.Typers$Typer.tryTypedArgs$1(Typers.scala:4530)
	at scala.tools.nsc.typechecker.Typers$Typer.onError$2(Typers.scala:4583)
	at scala.tools.nsc.typechecker.Typers$Typer.tryTypedApply$1(Typers.scala:4602)
	at scala.tools.nsc.typechecker.Typers$Typer.normalTypedApply$1(Typers.scala:4650)
	at scala.tools.nsc.typechecker.Typers$Typer.typedApply$1(Typers.scala:4686)
	at scala.tools.nsc.typechecker.Typers$Typer.typedInAnyMode$1(Typers.scala:5452)
	at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:5469)
	at scala.tools.nsc.typechecker.Typers$Typer.runTyper$1(Typers.scala:5505)
	at scala.tools.nsc.typechecker.Typers$Typer.typedInternal(Typers.scala:5535)
	at scala.tools.nsc.typechecker.Typers$Typer.body$2(Typers.scala:5479)
	at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5483)
	at scala.tools.nsc.typechecker.Typers$Typer.typedBlock(Typers.scala:2445)
	at scala.tools.nsc.typechecker.Typers$Typer.$anonfun$typed1$91(Typers.scala:5427)
	at scala.tools.nsc.typechecker.Typers$Typer.$anonfun$typerWithLocalContext$1(Typers.scala:490)
	at scala.tools.nsc.typechecker.Contexts$ContextReporter.propagatingErrorsTo(Contexts.scala:1255)
	at scala.tools.nsc.typechecker.Typers$Typer.typerWithLocalContext(Typers.scala:490)
	at scala.tools.nsc.typechecker.Typers$Typer.typedOutsidePatternMode$1(Typers.scala:5427)
	at scala.tools.nsc.typechecker.Typers$Typer.typedInAnyMode$1(Typers.scala:5462)
	at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:5469)
	at scala.tools.nsc.typechecker.Typers$Typer.runTyper$1(Typers.scala:5505)
	at scala.tools.nsc.typechecker.Typers$Typer.typedInternal(Typers.scala:5535)
	at scala.tools.nsc.typechecker.Typers$Typer.body$2(Typers.scala:5479)
	at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5483)
	at scala.tools.nsc.typechecker.Typers$Typer.transformedOrTyped(Typers.scala:5714)
	at scala.tools.nsc.typechecker.Typers$Typer.typedDefDef(Typers.scala:2275)
	at scala.tools.nsc.typechecker.Typers$Typer.typedMemberDef$1(Typers.scala:5417)
	at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:5468)
	at scala.tools.nsc.typechecker.Typers$Typer.runTyper$1(Typers.scala:5505)
	at scala.tools.nsc.typechecker.Typers$Typer.typedInternal(Typers.scala:5535)
	at scala.tools.nsc.typechecker.Typers$Typer.body$2(Typers.scala:5479)
	at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5483)
	at scala.tools.nsc.typechecker.Typers$Typer.typedByValueExpr(Typers.scala:5564)
	at scala.tools.nsc.typechecker.Typers$Typer.typedStat$1(Typers.scala:3063)
	at scala.tools.nsc.typechecker.Typers$Typer.$anonfun$typedStats$8(Typers.scala:3192)
	at scala.collection.immutable.List.loop$1(List.scala:173)
	at scala.collection.immutable.List.mapConserve(List.scala:189)
	at scala.tools.nsc.typechecker.Typers$Typer.typedStats(Typers.scala:3192)
	at scala.tools.nsc.typechecker.Typers$Typer.typedTemplate(Typers.scala:1980)
	at scala.tools.nsc.typechecker.Typers$Typer.typedModuleDef(Typers.scala:1851)
	at scala.tools.nsc.typechecker.Typers$Typer.typedMemberDef$1(Typers.scala:5419)
	at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:5468)
	at scala.tools.nsc.typechecker.Typers$Typer.runTyper$1(Typers.scala:5505)
	at scala.tools.nsc.typechecker.Typers$Typer.typedInternal(Typers.scala:5535)
	at scala.tools.nsc.typechecker.Typers$Typer.body$2(Typers.scala:5479)
	at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5483)
	at scala.tools.nsc.typechecker.Typers$Typer.typedByValueExpr(Typers.scala:5564)
	at scala.tools.nsc.typechecker.Typers$Typer.typedStat$1(Typers.scala:3063)
	at scala.tools.nsc.typechecker.Typers$Typer.$anonfun$typedStats$8(Typers.scala:3192)
	at scala.collection.immutable.List.loop$1(List.scala:173)
	at scala.collection.immutable.List.mapConserve(List.scala:189)
	at scala.tools.nsc.typechecker.Typers$Typer.typedStats(Typers.scala:3192)
	at scala.tools.nsc.typechecker.Typers$Typer.typedPackageDef$1(Typers.scala:5118)
	at scala.tools.nsc.typechecker.Typers$Typer.typedMemberDef$1(Typers.scala:5421)
	at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:5468)
	at scala.tools.nsc.typechecker.Typers$Typer.runTyper$1(Typers.scala:5505)
	at scala.tools.nsc.typechecker.Typers$Typer.typedInternal(Typers.scala:5535)
	at scala.tools.nsc.typechecker.Typers$Typer.body$2(Typers.scala:5479)
	at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5483)
	at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5560)
	at scala.tools.nsc.typechecker.Analyzer$typerFactory$$anon$3.apply(Analyzer.scala:102)
	at scala.tools.nsc.Global$GlobalPhase.$anonfun$applyPhase$1(Global.scala:402)
	at scala.tools.nsc.Global$GlobalPhase.withCurrentUnitNoLog(Global.scala:395)
	at scala.tools.nsc.Global$GlobalPhase.withCurrentUnit(Global.scala:386)
	at scala.tools.nsc.Global$GlobalPhase.applyPhase(Global.scala:402)
	at scala.tools.nsc.typechecker.Analyzer$typerFactory$$anon$3.$anonfun$run$1(Analyzer.scala:94)
	at scala.tools.nsc.typechecker.Analyzer$typerFactory$$anon$3.$anonfun$run$1$adapted(Analyzer.scala:93)
	at scala.collection.Iterator.foreach(Iterator.scala:932)
	at scala.collection.Iterator.foreach$(Iterator.scala:932)
	at scala.collection.AbstractIterator.foreach(Iterator.scala:1409)
	at scala.tools.nsc.typechecker.Analyzer$typerFactory$$anon$3.run(Analyzer.scala:93)
	at scala.tools.nsc.Global$Run.compileUnitsInternal(Global.scala:1404)
	at scala.tools.nsc.Global$Run.compileUnits(Global.scala:1389)
	at scala.tools.nsc.Global$Run.compileSources(Global.scala:1384)
	at scala.tools.nsc.Global$Run.compile(Global.scala:1478)
	at scala.tools.nsc.Driver.doCompile(Driver.scala:35)
	at scala.tools.nsc.MainClass.doCompile(Main.scala:24)
	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)


$ cat abc.scala
import scala.reflect.macros.blackbox.Context
object Impls {
  def foreach(c: Context)(f: c.Expr[Int => Unit]): c.Expr[Unit] = {
    object utils extends Utils { val context: c.type = c }
    import utils._
    import c.universe._
    import Flag._
    val initName = termNames.CONSTRUCTOR
    c.Expr(c.prefix.tree match {
      case lo(Select(New(tpt), initName), List(lo, hi)) if tpt.symbol.fullName == "Range" =>
        val iname = TermName("$i")
        val hname = TermName("$h")
        def iref = Ident(iname)
        def href = Ident(hname)
        val labelname = TermName("$while")
        val cond = makeBinop(iref, "$less", href)
        val body = Block(List(makeApply(f.tree, List(iref))), Assign(iref, makeBinop(iref, "$plus", Literal(Constant(1)))))
        val generated = Block(List(ValDef(Modifiers(MUTABLE), iname, TypeTree(), lo), ValDef(Modifiers(), hname, TypeTree(), hi)), makeWhile(labelname, cond, body))
        generated
      case _ => Apply(Select(Typed(c.prefix.tree, Ident(TypeName("RangeDefault"))), TermName("foreach")), List(f.tree))
    })
  }
}
class Range(val from: Int, val to: Int) extends RangeDefault { override def foreach(f: Int => Unit): Unit = macro Impls.foreach }
object Test extends App { new Range(1, 10) foreach println }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions