@@ -1202,7 +1202,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
1202
1202
// necessary to force annotation trees to be computed.
1203
1203
sym.annotations.foreach(_.ensureCompleted)
1204
1204
lazy val annotCtx = {
1205
- val c = ctx.outersIterator.dropWhile(_.owner == sym).next
1205
+ val c = ctx.outersIterator.dropWhile(_.owner == sym).next()
1206
1206
c.property(ExprOwner ) match {
1207
1207
case Some (exprOwner) if c.owner.isClass =>
1208
1208
// We need to evaluate annotation arguments in an expression context, since
@@ -1737,7 +1737,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
1737
1737
def tryAlternatively [T ](op1 : Context => T )(op2 : Context => T )(implicit ctx : Context ): T =
1738
1738
tryEither(op1) { (failedVal, failedState) =>
1739
1739
tryEither(op2) { (_, _) =>
1740
- failedState.commit
1740
+ failedState.commit()
1741
1741
failedVal
1742
1742
}
1743
1743
}
@@ -1858,9 +1858,10 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
1858
1858
1859
1859
def methodStr = err.refStr(methPart(tree).tpe)
1860
1860
1861
- def missingArgs = errorTree(tree,
1862
- em """ missing arguments for $methodStr
1863
- |follow this method with `_' if you want to treat it as a partially applied function """ )
1861
+ def missingArgs (mt : MethodType ) = {
1862
+ ctx.error(em " missing arguments for $methodStr" , tree.pos)
1863
+ tree.withType(mt.resultType)
1864
+ }
1864
1865
1865
1866
def adaptOverloaded (ref : TermRef ) = {
1866
1867
val altDenots = ref.denot.alternatives
@@ -2040,6 +2041,22 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
2040
2041
def isExpandableApply =
2041
2042
defn.isImplicitFunctionClass(tree.symbol.maybeOwner) && defn.isFunctionType(ptNorm)
2042
2043
2044
+ /** Is reference to this symbol `f` automatically expanded to `f()`? */
2045
+ def isAutoApplied (sym : Symbol ): Boolean = {
2046
+ def test (sym1 : Symbol ) =
2047
+ sym1.is(JavaDefined ) ||
2048
+ sym1.owner == defn.AnyClass ||
2049
+ sym1 == defn.Object_clone
2050
+ sym.isConstructor ||
2051
+ test(sym) ||
2052
+ sym.allOverriddenSymbols.exists(test) ||
2053
+ sym.owner.is(Scala2x ) || // need to exclude Scala-2 compiled symbols for now, since the
2054
+ // Scala library does not always follow the right conventions.
2055
+ // Examples are: isWhole(), toInt(), toDouble() in BigDecimal, Numeric, RichInt, ScalaNumberProxy.
2056
+ ctx.testScala2Mode(em " ${sym.showLocated} requires () argument " , tree.pos,
2057
+ patch(tree.pos.endPos, " ()" ))
2058
+ }
2059
+
2043
2060
// Reasons NOT to eta expand:
2044
2061
// - we reference a constructor
2045
2062
// - we are in a patterm
@@ -2049,12 +2066,12 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
2049
2066
! ctx.mode.is(Mode .Pattern ) &&
2050
2067
! (isSyntheticApply(tree) && ! isExpandableApply))
2051
2068
typed(etaExpand(tree, wtp, arity), pt)
2052
- else if (wtp.paramInfos.isEmpty)
2069
+ else if (wtp.paramInfos.isEmpty && isAutoApplied(tree.symbol) )
2053
2070
adaptInterpolated(tpd.Apply (tree, Nil ), pt, EmptyTree )
2054
2071
else if (wtp.isImplicit)
2055
2072
err.typeMismatch(tree, pt)
2056
2073
else
2057
- missingArgs
2074
+ missingArgs(wtp)
2058
2075
case _ =>
2059
2076
ctx.typeComparer.GADTused = false
2060
2077
if (defn.isImplicitFunctionClass(wtp.underlyingClassRef(refinementOK = false ).classSymbol) &&
@@ -2093,11 +2110,12 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
2093
2110
else
2094
2111
tree
2095
2112
}
2096
- else if (wtp.isInstanceOf [MethodType ]) missingArgs
2097
- else {
2098
- typr.println(i " adapt to subtype ${tree.tpe} !<:< $pt" )
2099
- // typr.println(TypeComparer.explained(implicit ctx => tree.tpe <:< pt))
2100
- adaptToSubType(wtp)
2113
+ else wtp match {
2114
+ case wtp : MethodType => missingArgs(wtp)
2115
+ case _ =>
2116
+ typr.println(i " adapt to subtype ${tree.tpe} !<:< $pt" )
2117
+ // typr.println(TypeComparer.explained(implicit ctx => tree.tpe <:< pt))
2118
+ adaptToSubType(wtp)
2101
2119
}
2102
2120
}
2103
2121
/** Adapt an expression of constant type to a different constant type `tpe`. */
0 commit comments