From 33b499cd04342a49bd5c4f5bf0e2fab88b69069c Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Sun, 10 Mar 2013 09:11:50 +0100 Subject: 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. --- test/files/pos/t7233.scala | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 test/files/pos/t7233.scala (limited to 'test/files/pos') diff --git a/test/files/pos/t7233.scala b/test/files/pos/t7233.scala new file mode 100644 index 0000000000..ae15c08c35 --- /dev/null +++ b/test/files/pos/t7233.scala @@ -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 _ +} -- cgit v1.2.3 From 41e3b89c6d636164f48a2c2d8e8867201075cdae Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Sun, 10 Mar 2013 10:06:00 +0100 Subject: SI-7233 Account for aliased imports in Erasure When we discard the fiction of `scala.Any`. --- src/compiler/scala/tools/nsc/transform/Erasure.scala | 2 +- test/files/pos/t7233b.scala | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 test/files/pos/t7233b.scala (limited to 'test/files/pos') diff --git a/src/compiler/scala/tools/nsc/transform/Erasure.scala b/src/compiler/scala/tools/nsc/transform/Erasure.scala index cb5268c422..ead6ef288c 100644 --- a/src/compiler/scala/tools/nsc/transform/Erasure.scala +++ b/src/compiler/scala/tools/nsc/transform/Erasure.scala @@ -781,7 +781,7 @@ abstract class Erasure extends AddInterfaces else if (tree.symbol == Any_isInstanceOf) adaptMember(atPos(tree.pos)(Select(qual, Object_isInstanceOf))) else if (tree.symbol.owner == AnyClass) - adaptMember(atPos(tree.pos)(Select(qual, getMember(ObjectClass, name)))) + adaptMember(atPos(tree.pos)(Select(qual, getMember(ObjectClass, tree.symbol.name)))) else { var qual1 = typedQualifier(qual) if ((isPrimitiveValueType(qual1.tpe) && !isPrimitiveValueMember(tree.symbol)) || diff --git a/test/files/pos/t7233b.scala b/test/files/pos/t7233b.scala new file mode 100644 index 0000000000..927c7fcfd1 --- /dev/null +++ b/test/files/pos/t7233b.scala @@ -0,0 +1,8 @@ +object Test { + // crash + def foo(a: Any) = { import a.{toString => toS}; toS } + + // okay + def ok1(a: String) = { import a.{isInstanceOf => iio}; iio[String] } + def ok2(a: Int) = { import a.{toInt => ti}; ti } +} -- cgit v1.2.3