Skip to content

Commit 267650c

Browse files
committed
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.
1 parent df88808 commit 267650c

File tree

3 files changed

+56
-9
lines changed

3 files changed

+56
-9
lines changed

src/compiler/scala/tools/nsc/typechecker/Typers.scala

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,15 +1044,21 @@ trait Typers extends Modes with Adaptations with Tags {
10441044

10451045
def insertApply(): Tree = {
10461046
assert(!inHKMode(mode), modeString(mode)) //@M
1047-
val qual = adaptToName(tree, nme.apply) match {
1048-
case id @ Ident(_) =>
1049-
val pre = if (id.symbol.owner.isPackageClass) id.symbol.owner.thisType
1050-
else if (id.symbol.owner.isClass)
1051-
context.enclosingSubClassContext(id.symbol.owner).prefix
1052-
else NoPrefix
1053-
stabilize(id, pre, EXPRmode | QUALmode, WildcardType)
1054-
case sel @ Select(qualqual, _) =>
1055-
stabilize(sel, qualqual.tpe, EXPRmode | QUALmode, WildcardType)
1047+
val adapted = adaptToName(tree, nme.apply)
1048+
def stabilize0(pre: Type): Tree = stabilize(adapted, pre, EXPRmode | QUALmode, WildcardType)
1049+
// TODO reconcile the overlap between Typers#stablize and TreeGen.stabilize
1050+
val qual = adapted match {
1051+
case This(_) =>
1052+
gen.stabilize(adapted)
1053+
case Ident(_) =>
1054+
val owner = adapted.symbol.owner
1055+
val pre =
1056+
if (owner.isPackageClass) owner.thisType
1057+
else if (owner.isClass) context.enclosingSubClassContext(owner).prefix
1058+
else NoPrefix
1059+
stabilize0(pre)
1060+
case Select(qualqual, _) =>
1061+
stabilize0(qualqual.tpe)
10561062
case other =>
10571063
other
10581064
}

test/files/run/t6206.check

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
outer
2+
outer
3+
inner
4+
inner

test/files/run/t6206.scala

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
class Outer {
2+
def apply( position : Inner ) {}
3+
class Inner
4+
5+
this.apply(new Inner)
6+
this (new Inner) // error,
7+
}
8+
9+
10+
class Outer1 {
11+
12+
self =>
13+
14+
def apply( position : Inner ) : String = "outer"
15+
16+
class Inner( ) {
17+
18+
def apply(arg: Inner): String = "inner"
19+
20+
def testMe = {
21+
List(
22+
self.apply( this ), // a) this works
23+
self( this ), // b) this does not work!
24+
this apply this,
25+
this(this)
26+
) foreach println
27+
}
28+
}
29+
}
30+
31+
object Test {
32+
def main(args: Array[String]): Unit = {
33+
val o = new Outer1
34+
val i = new o.Inner
35+
i.testMe
36+
}
37+
}

0 commit comments

Comments
 (0)