summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala12
-rw-r--r--test/files/pos/t5259.scala21
2 files changed, 27 insertions, 6 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala b/src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala
index bef6f13bc3..8ae254d35d 100644
--- a/src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/NamesDefaults.scala
@@ -158,20 +158,20 @@ trait NamesDefaults { self: Analyzer =>
// it stays in Vegas: SI-5720, SI-5727
qual changeOwner (blockTyper.context.owner -> sym)
+ val newQual = atPos(qual.pos.focus)(blockTyper.typedQualifier(Ident(sym.name)))
var baseFunTransformed = atPos(baseFun.pos.makeTransparent) {
- // don't use treeCopy: it would assign opaque position.
- val f = Select(gen.mkAttributedRef(sym), selected)
- .setType(baseFun1.tpe).setSymbol(baseFun1.symbol)
+ // setSymbol below is important because the 'selected' function might be overloaded. by
+ // assigning the correct method symbol, typedSelect will just assign the type. the reason
+ // to still call 'typed' is to correctly infer singleton types, SI-5259.
+ val f = blockTyper.typedOperator(Select(newQual, selected).setSymbol(baseFun1.symbol))
if (funTargs.isEmpty) f
else TypeApply(f, funTargs).setType(baseFun.tpe)
}
val b = Block(List(vd), baseFunTransformed)
.setType(baseFunTransformed.tpe).setPos(baseFun.pos)
-
- val defaultQual = Some(atPos(qual.pos.focus)(gen.mkAttributedRef(sym)))
context.namedApplyBlockInfo =
- Some((b, NamedApplyInfo(defaultQual, defaultTargs, Nil, blockTyper)))
+ Some((b, NamedApplyInfo(Some(newQual), defaultTargs, Nil, blockTyper)))
b
}
diff --git a/test/files/pos/t5259.scala b/test/files/pos/t5259.scala
new file mode 100644
index 0000000000..d33c4dd6a7
--- /dev/null
+++ b/test/files/pos/t5259.scala
@@ -0,0 +1,21 @@
+class A[T]
+class B {
+ def m(a: A[this.type] = new A[this.type]) { }
+}
+
+class C {
+ def foo(a: Int, b: Int = 0) = 0
+ def foo() = 0
+}
+
+object Test {
+ def newB = new B
+ newB.m()
+
+ val stableB = new B
+ stableB.m()
+
+ def f {
+ println((new C).foo(0))
+ }
+}