From fb061f22d4c35df626d9651e017820a11f8fe56e Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Tue, 31 May 2011 09:02:29 +0000 Subject: A getter with type params is still a getter. There were two distinct bugs in here, which if I ran the world would be a wakeup call that robust software cannot emerge from thousands of lines of low-level AST matching. In case you are frozen in suspense: I do not run the world. Review by moors. --- src/compiler/scala/reflect/internal/TreeInfo.scala | 9 +++++---- src/compiler/scala/tools/nsc/typechecker/Typers.scala | 2 +- test/files/pos/bug4237.scala | 6 ++++++ 3 files changed, 12 insertions(+), 5 deletions(-) create mode 100644 test/files/pos/bug4237.scala diff --git a/src/compiler/scala/reflect/internal/TreeInfo.scala b/src/compiler/scala/reflect/internal/TreeInfo.scala index d61ac792cc..059a95f271 100644 --- a/src/compiler/scala/reflect/internal/TreeInfo.scala +++ b/src/compiler/scala/reflect/internal/TreeInfo.scala @@ -95,10 +95,11 @@ abstract class TreeInfo { false } - def mayBeVarGetter(sym: Symbol) = sym.info match { - case NullaryMethodType(_) => sym.owner.isClass && !sym.isStable - case mt @ MethodType(_, _) => mt.isImplicit && sym.owner.isClass && !sym.isStable - case _ => false + def mayBeVarGetter(sym: Symbol): Boolean = sym.info match { + case NullaryMethodType(_) => sym.owner.isClass && !sym.isStable + case PolyType(_, NullaryMethodType(_)) => sym.owner.isClass && !sym.isStable + case mt @ MethodType(_, _) => mt.isImplicit && sym.owner.isClass && !sym.isStable + case _ => false } def isVariableOrGetter(tree: Tree) = { diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index c43fa377a4..114fa7ed1b 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -3120,7 +3120,7 @@ trait Typers extends Modes { return fail if (treeInfo.mayBeVarGetter(varsym)) { - lhs1 match { + treeInfo.methPart(lhs1) match { case Select(qual, name) => val sel = Select(qual, nme.getterToSetter(name.toTermName)) setPos lhs.pos val app = Apply(sel, List(rhs)) setPos tree.pos diff --git a/test/files/pos/bug4237.scala b/test/files/pos/bug4237.scala new file mode 100644 index 0000000000..fcf6eb8bf1 --- /dev/null +++ b/test/files/pos/bug4237.scala @@ -0,0 +1,6 @@ +class A { + (new { def field = 0; def field_=(i: Int) = () }).field = 5 // compiles as expected + (new { def field(implicit i: Int) = 0; def field_=(i: Int) = () }).field = 5 // compiles even with implicit params on getter + (new { def field = 0; def field_=[T](i: Int) = () }).field = 5 // compiles with type param on setter + (new { def field[T] = 0; def field_=(i: Int) = () }).field = 5 // DOESN'T COMPILE +} \ No newline at end of file -- cgit v1.2.3