Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[backport] Fix for SI-6206, inconsistency with apply.

Squashed commit of the following:

commit f6bbf85150cfd7e461989ec1d6765ff4b4aeba51
Author: Paul Phillips <paulp@improving.org>
Date:   Mon Oct 1 09:10:45 2012 -0700

    Fix for SI-6206, inconsistency with apply.

    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.
    (cherry picked from commit 267650c)
  • Loading branch information...
commit 11ac963c811f2a9a00fac5bb874efeaab35c4041 1 parent 2fa859e
@retronym retronym authored
View
24 src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -1052,15 +1052,21 @@ trait Typers extends Modes with Adaptations with Tags {
def insertApply(): Tree = {
assert(!inHKMode(mode), modeString(mode)) //@M
- val qual = adaptToName(tree, nme.apply) match {
- case id @ Ident(_) =>
- val pre = if (id.symbol.owner.isPackageClass) id.symbol.owner.thisType
- else if (id.symbol.owner.isClass)
- context.enclosingSubClassContext(id.symbol.owner).prefix
- else NoPrefix
- stabilize(id, pre, EXPRmode | QUALmode, WildcardType)
- case sel @ Select(qualqual, _) =>
- stabilize(sel, qualqual.tpe, EXPRmode | QUALmode, WildcardType)
+ val adapted = adaptToName(tree, nme.apply)
+ def stabilize0(pre: Type): Tree = stabilize(adapted, pre, EXPRmode | QUALmode, WildcardType)
+ // TODO reconcile the overlap between Typers#stablize and TreeGen.stabilize
+ val qual = adapted match {
+ case This(_) =>
+ gen.stabilize(adapted)
+ case Ident(_) =>
+ val owner = adapted.symbol.owner
+ 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 =>
other
}
View
4 test/files/run/t6206.check
@@ -0,0 +1,4 @@
+outer
+outer
+inner
+inner
View
37 test/files/run/t6206.scala
@@ -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 11ac963

Please sign in to comment.
Something went wrong with that request. Please try again.