From 145ac696c9a2cb26655e954b4a6be879a3500641 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 27 Feb 2017 12:35:37 +0100 Subject: [PATCH] Fix #2033: Improve handling of unresolved overloaded arguments --- .../dotty/tools/dotc/typer/Applications.scala | 11 +++++++++- tests/neg/i2033.scala | 21 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 tests/neg/i2033.scala diff --git a/compiler/src/dotty/tools/dotc/typer/Applications.scala b/compiler/src/dotty/tools/dotc/typer/Applications.scala index de017961ae7f..e9df12b42a96 100644 --- a/compiler/src/dotty/tools/dotc/typer/Applications.scala +++ b/compiler/src/dotty/tools/dotc/typer/Applications.scala @@ -450,7 +450,16 @@ trait Applications extends Compatibility { self: Typer with Dynamic => def typedArg(arg: Arg, formal: Type): Arg = arg def addArg(arg: TypedArg, formal: Type) = - ok = ok & isCompatible(argType(arg, formal), formal) + ok = ok & { + argType(arg, formal) match { + case ref: TermRef if ref.denot.isOverloaded => + // in this case we could not resolve overloading because no alternative + // matches expected type + false + case argtpe => + isCompatible(argtpe, formal) + } + } def makeVarArg(n: Int, elemFormal: Type) = {} def fail(msg: => Message, arg: Arg) = ok = false diff --git a/tests/neg/i2033.scala b/tests/neg/i2033.scala new file mode 100644 index 000000000000..b28a0d99e5be --- /dev/null +++ b/tests/neg/i2033.scala @@ -0,0 +1,21 @@ +import java.io._ +import collection._ +object Test { + def check(obj: AnyRef): Unit = { + val bos = new ByteArrayOutputStream() + val out = new ObjectOutputStream(println) // error + val arr = bos toByteArray () + val in = (()) + val deser = () + val lhs = mutable LinkedHashSet () + check(lhs) + } +} + +// minimization +object Test2 { + class ObjectOutputStream(out: String) { + def this() = this("") + } + val out = new ObjectOutputStream(println) // error +}