Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No completions returned on wildcard in method with multiple params #12909

Open
tgodzik opened this issue Nov 20, 2023 · 5 comments
Open

No completions returned on wildcard in method with multiple params #12909

tgodzik opened this issue Nov 20, 2023 · 5 comments

Comments

@tgodzik
Copy link

tgodzik commented Nov 20, 2023

Reproduction steps

class Foo {
  def Bar: Double = 2.0
  def Baz: Double = 1.0
}

object Bar {
    def higherOrder2(f: Foo => Double, s: String): Nothing = ???
   higherOrder2(_.@@)
}

Problem

When trying to get completions after _. we don't get any results. I suspect it's because we are missing all the arguments. This works for one argument function.

I think there was a similar issue in Scala 3, but it could have been fix by Martin in https://github.com/lampepfl/dotty/pull/14695/files

Maybe it would be possible to backport those fixes to Scala 2 ? I think those parts haven't changed much. I will not have time to work on that unfortunately, but I was hoping this could be a quick look from someone more knowledgable about the compiler

@harpocrates
Copy link

I think a related broken example is

object MultiArg {
    def multiArg(f: (Double, Double) => Double): Nothing = ???
    multiArg(_.@@)
}

Here also, we get no completions after _..

@lrytz
Copy link
Member

lrytz commented Dec 6, 2023

Thanks both of you, I hope I'll find some time soon to take a look.

@SethTisue SethTisue added this to the 2.13.13 milestone Dec 7, 2023
@lrytz
Copy link
Member

lrytz commented Dec 7, 2023

In the first example

class C { def fun = 0 }
def h(f: C => Int, s: String) = 0
h(x => x.f@@)

The parser will create an AST f(x => x.f) and attempt to type check it. This fails with a not enough arguments error when type checking, which initally leaves the argument x => ... untyped.

The argument is then type checked in the error handler but without an expected type (https://github.com/scala/scala/blob/v2.13.12/src/compiler/scala/tools/nsc/typechecker/Typers.scala#L5064). In type-checking x => x.f without expected type we have no information about the type of x, so completions cannot find any results for x.f@@.

Maybe we can do some more best effor error recovery in interactive mode. So far I couldn't spot a flag or something to know if we're in an interacitve.Global or not.

The second example might be slightly different, haven't checked yet.

@tgodzik
Copy link
Author

tgodzik commented Dec 7, 2023

Thanks for looking into this!

Maybe we can do some more best effor error recovery in interactive mode. So far I couldn't spot a flag or something to know if we're in an interacitve.Global or not.

I think we would need to add one, though for Scala 3 I don't think it is used. The tree doesn't matter much if an error is reported anyway, so the whole compilation still fails.

@lrytz
Copy link
Member

lrytz commented Dec 7, 2023

I think we would need to add one, though for Scala 3 I don't think it is used. The tree doesn't matter much if an error is reported anyway, so the whole compilation still fails.

Yes, but I believe there are some cases where type checking method arguments with an expected type fails, but then typing them without succeeds and compilation continues. So we're not necessarily in an error state yet.

@SethTisue SethTisue modified the milestones: 2.13.13, 2.13.14 Jan 22, 2024
@SethTisue SethTisue modified the milestones: 2.13.14, 2.13.15 Mar 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants