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

When falling back to adapt without an expected type, use of resetAttrs leads to unhygenic rebinding

    Details

      Description

      class C /*#1*/{
        implicit def conversion(m: Int)(implicit nada: Nothing): String = ???
      
        class C /*#2*/ { // rename class to get correct error.
          locally(0 : String) // "value conversion is not a member of C.this.C"
        }
      }
      

      The offending code:

      // Typer#adapt
      case _ =>
        debuglog("fallback on implicits: " + tree + "/" + resetAllAttrs(original))
        val tree1 = typed(resetAllAttrs(original), mode, WildcardType)
        // Q: `typed` already calls `pluginsTyped` and `adapt`. the only difference here is that
        // we pass `EmptyTree` as the `original`. intended? added in 2009 (53d98e7d42) by martin.
        tree1.tpe = pluginsTyped(tree1.tpe, this, tree1, mode, pt)
        if (tree1.isEmpty) tree1 else adapt(tree1, mode, pt, EmptyTree)
      

      The winning implicit conversion is inferred as a symful Select(This(C#1), "conversion"). The resetAllAttrs brutalizes this tree, and upon retypechecking we end up with This(C#2).

      resetLocalAttrs seems like a better option here.

      The same problem arises with the two classes share the name "$anon".

      trait T; trait U
      new T {
        implicit def conversion(m: Int)(implicit nada: Nothing): String = ???
      
        new U { // rename class to get correct error.
          locally(0 : String) // "value conversion is not a member of U"
        }
      }
      

        Activity

        Show
        Jason Zaugg added a comment - - edited Original report: https://groups.google.com/d/msg/scala-internals/t6cpY7fGng4/0CIfXj1e-UEJ https://github.com/retronym/scala/tree/ticket/7519 https://github.com/scala/scala/pull/2596
        Hide
        Adriaan Moors added a comment -

        Unassigning and rescheduling to M6 as previous deadline was missed.

        Show
        Adriaan Moors added a comment - Unassigning and rescheduling to M6 as previous deadline was missed.
        Hide
        Mark Harrah added a comment -

        The commit (32b5d50d6635320f448c92c27bc6df3acbb04451) in Jason's pull request, included in 2.11.0-M4, fixes sbt issue https://github.com/sbt/sbt/issues/914 (unless I screwed up bisect). A partest test covering the sbt issue is here: https://github.com/harrah/scala/commit/6da26cbbe7c2557a5097573fa9bd09ded1fe9367. Useful to submit as a pull request? Can the fix be backported to 2.10.x?

        Show
        Mark Harrah added a comment - The commit (32b5d50d6635320f448c92c27bc6df3acbb04451) in Jason's pull request, included in 2.11.0-M4, fixes sbt issue https://github.com/sbt/sbt/issues/914 (unless I screwed up bisect). A partest test covering the sbt issue is here: https://github.com/harrah/scala/commit/6da26cbbe7c2557a5097573fa9bd09ded1fe9367 . Useful to submit as a pull request? Can the fix be backported to 2.10.x?
        Hide
        Jason Zaugg added a comment - - edited

        Thanks for the precise bisection!

        Please submit the test case. I suppose that fix has lived in master for a while without anything blowing up, so we might accept the backport, too, given that it helps SBT usability. That said, almost no-one has tried master in anger as we're only just in a position to start building Scalaz, Specs et al.

        Show
        Jason Zaugg added a comment - - edited Thanks for the precise bisection! Please submit the test case. I suppose that fix has lived in master for a while without anything blowing up, so we might accept the backport, too, given that it helps SBT usability. That said, almost no-one has tried master in anger as we're only just in a position to start building Scalaz, Specs et al.
        Hide
        Jason Zaugg added a comment -
        Show
        Jason Zaugg added a comment - Backport: https://github.com/scala/scala/pull/3072
        Show
        Adriaan Moors added a comment - https://github.com/scala/scala/pull/3072

          People

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

            Dates

            • Created:
              Updated:
              Resolved:

              Development