Scala Programming Language
  1. Scala Programming Language
  2. SI-7603

annotations: occasional spurious "Ann is abstract; cannot be instantiated " error

    Details

      Description

      We've had reports of:

      We are getting this error from time to time:
      error: trait Test is abstract; cannot be instantiated
      11:09:50 [ant:scalac] @Test def testClientRequestNum = {
      11:09:50 [ant:scalac] ^

      I see the error is similar to one we spotted on a build here: https://github.com/scala/scala/pull/2107#issuecomment-13408939

      The error suggests that the annotation is binding to the wrong symbol on the classpath has the same name.

      I can't reproduce it, but I think I've spotted the problem. Can you?

      // need to be lazy, #1782. beforeTyper to allow inferView in annotation args, SI-5892.
      AnnotationInfo lazily {
        val context1 = typer.context.make(ann)
        context1.setReportErrors()
        enteringTyper(newTyper(context1) typedAnnotation ann)
      }
      

        Activity

        Hide
        Jason Zaugg added a comment - - edited

        I'm still unable to craft a test to trigger this. My hypothesis is that the field `Typer#context` is mutated between the point when the lazy annotation info is created and when it is forced.

        A few breadcrumbs for code that might be of interest:

            // Namers.scala
            def enterSyms(trees: List[Tree]): Namer = {
              trees.foldLeft(this: Namer) { (namer, t) =>
                val ctx = namer enterSym t
                // for Import trees, enterSym returns a changed context, so we need a new namer
                if (ctx eq namer.context) namer
                else newNamer(ctx)
              }
            }
        
                  // Typer#typeStats
                  stat match {
                    case imp @ Import(_, _) =>
                      imp.symbol.initialize
                      if (!imp.symbol.isError) {
                        context = context.makeNewImport(imp)
                        typedImport(imp)
                      } else EmptyTree
        
        Show
        Jason Zaugg added a comment - - edited I'm still unable to craft a test to trigger this. My hypothesis is that the field `Typer#context` is mutated between the point when the lazy annotation info is created and when it is forced. A few breadcrumbs for code that might be of interest: // Namers.scala def enterSyms(trees: List[Tree]): Namer = { trees.foldLeft(this: Namer) { (namer, t) => val ctx = namer enterSym t // for Import trees, enterSym returns a changed context, so we need a new namer if (ctx eq namer.context) namer else newNamer(ctx) } } // Typer#typeStats stat match { case imp @ Import(_, _) => imp.symbol.initialize if (!imp.symbol.isError) { context = context.makeNewImport(imp) typedImport(imp) } else EmptyTree
        Show
        Adriaan Moors added a comment - https://github.com/scala/scala/pull/2680
        Show
        Jason Zaugg added a comment - https://github.com/scala/scala/pull/2842/files

          People

          • Assignee:
            Jason Zaugg
            Reporter:
            Jason Zaugg
          • Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development