Skip to content

Commit

Permalink
Fix for SI-6206, inconsistency with apply.
Browse files Browse the repository at this point in the history
The code part of this patch is 100% written by retronym, who
apparently has higher standards than I do because I found it just
lying around in his repository. I think I'll go pick through his
trash and see if he's throwing away any perfectly good muffins.

I made the test case more exciting so as to feel useful.
  • Loading branch information
paulp committed Oct 14, 2012
1 parent df88808 commit 267650c
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/compiler/scala/tools/nsc/typechecker/Typers.scala
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -1044,15 +1044,21 @@ trait Typers extends Modes with Adaptations with Tags {


def insertApply(): Tree = { def insertApply(): Tree = {
assert(!inHKMode(mode), modeString(mode)) //@M assert(!inHKMode(mode), modeString(mode)) //@M
val qual = adaptToName(tree, nme.apply) match { val adapted = adaptToName(tree, nme.apply)
case id @ Ident(_) => def stabilize0(pre: Type): Tree = stabilize(adapted, pre, EXPRmode | QUALmode, WildcardType)
val pre = if (id.symbol.owner.isPackageClass) id.symbol.owner.thisType // TODO reconcile the overlap between Typers#stablize and TreeGen.stabilize
else if (id.symbol.owner.isClass) val qual = adapted match {
context.enclosingSubClassContext(id.symbol.owner).prefix case This(_) =>
else NoPrefix gen.stabilize(adapted)
stabilize(id, pre, EXPRmode | QUALmode, WildcardType) case Ident(_) =>
case sel @ Select(qualqual, _) => val owner = adapted.symbol.owner
stabilize(sel, qualqual.tpe, EXPRmode | QUALmode, WildcardType) val pre =
if (owner.isPackageClass) owner.thisType
else if (owner.isClass) context.enclosingSubClassContext(owner).prefix
else NoPrefix
stabilize0(pre)
case Select(qualqual, _) =>
stabilize0(qualqual.tpe)
case other => case other =>
other other
} }
Expand Down
4 changes: 4 additions & 0 deletions test/files/run/t6206.check
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,4 @@
outer
outer
inner
inner
37 changes: 37 additions & 0 deletions test/files/run/t6206.scala
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,37 @@
class Outer {
def apply( position : Inner ) {}
class Inner

this.apply(new Inner)
this (new Inner) // error,
}


class Outer1 {

self =>

def apply( position : Inner ) : String = "outer"

class Inner( ) {

def apply(arg: Inner): String = "inner"

def testMe = {
List(
self.apply( this ), // a) this works
self( this ), // b) this does not work!
this apply this,
this(this)
) foreach println
}
}
}

object Test {
def main(args: Array[String]): Unit = {
val o = new Outer1
val i = new o.Inner
i.testMe
}
}

0 comments on commit 267650c

Please sign in to comment.