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