Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions compiler/src/dotty/tools/dotc/core/SymDenotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1085,10 +1085,10 @@ object SymDenotations {
*/
def matchNullaryLoosely(using Context): Boolean = {
def test(sym: Symbol) =
sym.is(JavaDefined) ||
sym.owner == defn.AnyClass ||
sym == defn.Object_clone ||
sym.owner.is(Scala2x)
sym.is(JavaDefined)
|| sym.owner == defn.AnyClass
|| sym == defn.Object_clone
|| sym.owner.is(Scala2x) && sym.name != nme.apply
this.exists && (test(symbol) || allOverriddenSymbols.exists(test))
}

Expand Down
48 changes: 24 additions & 24 deletions compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4640,30 +4640,30 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
}

/** A synthetic apply should be eta-expanded if it is the apply of an implicit function
* class, and the expected type is a function type. This rule is needed so we can pass
* an implicit function to a regular function type. So the following is OK
*
* val f: implicit A => B = ???
* val g: A => B = f
*
* and the last line expands to
*
* val g: A => B = (x$0: A) => f.apply(x$0)
*
* One could be tempted not to eta expand the rhs, but that would violate the invariant
* that expressions of implicit function types are always implicit closures, which is
* exploited by ShortcutImplicits.
*
* On the other hand, the following would give an error if there is no implicit
* instance of A available.
*
* val x: AnyRef = f
*
* That's intentional, we want to fail here, otherwise some unsuccessful implicit searches
* would go undetected.
*
* Examples for these cases are found in run/implicitFuns.scala and neg/i2006.scala.
*/
* class, and the expected type is a function type. This rule is needed so we can pass
* an implicit function to a regular function type. So the following is OK
*
* val f: implicit A => B = ???
* val g: A => B = f
*
* and the last line expands to
*
* val g: A => B = (x$0: A) => f.apply(x$0)
*
* One could be tempted not to eta expand the rhs, but that would violate the invariant
* that expressions of implicit function types are always implicit closures, which is
* exploited by ShortcutImplicits.
*
* On the other hand, the following would give an error if there is no implicit
* instance of A available.
*
* val x: AnyRef = f
*
* That's intentional, we want to fail here, otherwise some unsuccessful implicit searches
* would go undetected.
*
* Examples for these cases are found in run/implicitFuns.scala and neg/i2006.scala.
*/
def adaptNoArgsUnappliedMethod(wtp: MethodType, functionExpected: Boolean, arity: Int): Tree = {
/** Is reference to this symbol `f` automatically expanded to `f()`? */
def isAutoApplied(sym: Symbol): Boolean =
Expand Down
8 changes: 8 additions & 0 deletions tests/neg/i21351.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
def f = () => 42

object X:
def apply() = 42

@main def Test =
f.apply // error
X.apply // error
Loading