Permalink
Browse files

SI-7233 Account for aliased imports in eta expansion.

Buggy:

    treeCopy.Select(sel, sel.qual, sel.name) setSymbol null
    Select(sel, sel.qual, sel.name)

Okay:

    treeCopy.Select(sel, sel.qual, sel.name)
    Select(sel, sel.qual, sel.symbol.name) // but doesn't copyAttrs!

It is an easy mistake to make, I've found one more occurance:

  def foo(a: Any) = { import a.{toString => toS}; toS }

    error: uncaught exception during compilation: scala.reflect.internal.FatalError
    scala.reflect.internal.FatalError: class Object does not have a member toS
        at scala.reflect.internal.Definitions$DefinitionsClass.scala$reflect$internal$Definitions$DefinitionsClass$$fatalMissingSymbol(Definitions.scala:1028)

A followup commit will address that problem.
  • Loading branch information...
1 parent 889020d commit 33b499cd04342a49bd5c4f5bf0e2fab88b69069c @retronym retronym committed Mar 10, 2013
Showing with 15 additions and 0 deletions.
  1. +1 −0 src/compiler/scala/tools/nsc/typechecker/EtaExpansion.scala
  2. +14 −0 test/files/pos/t7233.scala
@@ -101,6 +101,7 @@ trait EtaExpansion { self: Analyzer =>
case TypeApply(fn, args) =>
treeCopy.TypeApply(tree, liftoutPrefix(fn), args) setType null
case Select(qual, name) =>
+ val name = tree.symbol.name // account for renamed imports, SI-7233
treeCopy.Select(tree, liftout(qual, false), name) setSymbol NoSymbol setType null
case Ident(name) =>
tree
View
@@ -0,0 +1,14 @@
+object Foo {
+ def bar(i: Int) = i
+
+ def ol(i: Int) = i
+ def ol(i: String) = i
+}
+object Test {
+ import Foo.{ bar => quux, toString => bar, ol => olRenamed}
+
+ val f1 = quux _
+ val f1Typed: (Int => Int) = f1
+
+ val f2: String => String = olRenamed _
+}

0 comments on commit 33b499c

Please sign in to comment.