Skip to content
Open
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
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ object Typer {
* apply of a function class?
*/
private[typer] def isSyntheticApply(tree: tpd.Tree): Boolean = tree match {
case tree: tpd.Select => tree.hasAttachment(InsertedApply)
case _: (tpd.Select | tpd.Apply) => tree.hasAttachment(InsertedApply)
case TypeApply(fn, targs) => isSyntheticApply(fn) && targs.forall(_.isInstanceOf[tpd.InferredTypeTree])
case _ => false
}
Expand Down
6 changes: 6 additions & 0 deletions tests/neg/24782.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- [E050] Type Error: tests/neg/24782.scala:4:28 -----------------------------------------------------------------------
4 | def f(using pure: Pure) = S(s => pure(s)) // error (but no compiler crash / stack overflow)
| ^
| expression does not take more parameters
|
| longer explanation available when compiling with `-explain`
5 changes: 5 additions & 0 deletions tests/neg/24782.scala
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

checkfile is missing :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops, thanks, added

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
object S {
trait F[A]
type Pure = [a] => a => F[a]
def f(using pure: Pure) = S(s => pure(s)) // error (but no compiler crash / stack overflow)
}
4 changes: 2 additions & 2 deletions tests/pos/i14907.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ object Module {
case 1 => Any *: Fill[0]
}
extension[N <: Int] (f: Fun[N])
def apply: Fill[N] => Any = ???
def apply(): Fill[N] => Any = ???
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

per conversation on Slack, no, parameterless apply should not be used since the language reference only talks about parameterized insertions of apply, see the recent thread in compiler-development

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, then can we have a clear test that shows explicitly this. Something like:

object A:
  def apply: Int = ???

val x: Int = A // error: must call apply explicitly

This test and the other have too many elements in them that it is not clear what their purpose is.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to have some systematic tests of language features, yeah, but for that we'd need an unambiguous language reference first, the slack thread already mentions some corner cases like "what if apply is of a custom function-like type". :/

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but for that we'd need an unambiguous language reference first

I agree. If that is intended to be the case, and if you find the wording to be ambiguous, you can also update the wording to at least cover this case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

created #25504


Fun[1]()(???)
Fun[1]()()(???)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed on Slack, per §6.6 of the language ref, apply should only be used if there are parameters. This is the only positive test I could find in which this was happening.

}
Loading