diff options
author | Martin Odersky <odersky@gmail.com> | 2016-12-18 19:29:02 +0100 |
---|---|---|
committer | Felix Mulder <felix.mulder@gmail.com> | 2016-12-20 18:33:44 +0100 |
commit | 7c5e36b80e111d17910dbf122c02a458377656d1 (patch) | |
tree | 210ba0cde3e81925aab1af83ab1353c6606a1331 /compiler/src/dotty/tools/dotc/typer/Typer.scala | |
parent | 9c0df5aa3af3906913f6507e04078c32dd2a4742 (diff) | |
download | dotty-7c5e36b80e111d17910dbf122c02a458377656d1.tar.gz dotty-7c5e36b80e111d17910dbf122c02a458377656d1.tar.bz2 dotty-7c5e36b80e111d17910dbf122c02a458377656d1.zip |
More lenient handling of mixed parameterless and nullary methods
When faced with a denotation that combines parameterless and nullary method
definitions (toString is a common example), ignore any redundant () applications.
Diffstat (limited to 'compiler/src/dotty/tools/dotc/typer/Typer.scala')
-rw-r--r-- | compiler/src/dotty/tools/dotc/typer/Typer.scala | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index 07a27a498..d054fe803 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -1640,13 +1640,19 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit case _ => false } - /** Add apply node or implicit conversions. Two strategies are tried, and the first - * that is successful is picked. If neither of the strategies are successful, continues with - * `fallBack`. + /** Potentially add apply node or implicit conversions. Before trying either, + * if the function is applied to an empty parameter list (), we try + * + * 0th strategy: If `tree` overrides a nullary method, mark the prototype + * so that the argument is dropped and return `tree` itself. + * + * After that, two strategies are tried, and the firs that is successful is picked. + * If neither of the strategies are successful, continues with`fallBack`. * * 1st strategy: Try to insert `.apply` so that the result conforms to prototype `pt`. * This strategy is not tried if the prototype represents already * another `.apply` or `.apply()` selection. + * * 2nd strategy: If tree is a select `qual.name`, try to insert an implicit conversion * around the qualifier part `qual` so that the result conforms to the expected type * with wildcard result type. @@ -1661,8 +1667,15 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit def tryImplicit = tryInsertImplicitOnQualifier(tree, pt).getOrElse(fallBack) - if (isApplyProto(pt)) tryImplicit - else tryEither(tryApply(_))((_, _) => tryImplicit) + pt match { + case pt @ FunProto(Nil, _, _) + if tree.symbol.allOverriddenSymbols.exists(_.info.isNullaryMethod) => + pt.markAsDropped() + tree + case _ => + if (isApplyProto(pt)) tryImplicit + else tryEither(tryApply(_))((_, _) => tryImplicit) + } } /** If this tree is a select node `qual.name`, try to insert an implicit conversion |