Skip to content

Overloaded or recursive method test needs return type #3253

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

Closed
allanrenucci opened this issue Oct 4, 2017 · 6 comments
Closed

Overloaded or recursive method test needs return type #3253

allanrenucci opened this issue Oct 4, 2017 · 6 comments
Assignees
Labels
area:community build area:reporting Error reporting including formatting, implicit suggestions, etc itype:bug prio:low

Comments

@allanrenucci
Copy link
Contributor

This doesn't compile:

import Test.test

object Test {
  def test = "  " * 10
}
[info] Running dotty.tools.dotc.Main -d out tests/allan/Test.scala -classpath dotty-library_2.12-0.4.0-bin-SNAPSHOT-nonbootstrapped.jar
-- [E043] Syntax Error: tests/allan/Test.scala:4:13 ----------------------------
4 |  def test = "  " * 10
  |             ^^^^
  |             overloaded or recursive method test needs return type

Dotty is confused by the import

@odersky
Copy link
Contributor

odersky commented Oct 4, 2017

The error message could be better, but this is a true cyclic reference, so an error should be reported. The cyclic reference is:

  • in the body of test, we need to find an implicit on " " that provides the *.
  • we search the imports for any implicits
  • to search the import, we compute the member denotation of Test.test.
  • the denotations needs a type, which causes the return type of test to be computed again.

scalac avoids this because it does not compute types when taking members. But we do not want to go back there.

@odersky
Copy link
Contributor

odersky commented Oct 4, 2017

Remedy: Provide an explicit return type. That's good practice anyway.

@odersky odersky added prio:low area:reporting Error reporting including formatting, implicit suggestions, etc and removed prio:high area:typer labels Oct 4, 2017
@smarter
Copy link
Member

smarter commented Oct 4, 2017

How come the following works with Dotty then?

import Test._

object Test {
  def test = "  " * 10
}

@odersky
Copy link
Contributor

odersky commented Oct 5, 2017

It scans for all implicit members of Test before trying to compute any of them.

allanrenucci added a commit to dotty-staging/scalatest that referenced this issue Oct 5, 2017
odersky referenced this issue Oct 8, 2017
Fix #3252: Generalize constraint handling when harmonizing
allanrenucci added a commit to dotty-staging/scalatest that referenced this issue Oct 9, 2017
cheeseng pushed a commit to cheeseng/scalatest that referenced this issue Oct 11, 2017
allanrenucci added a commit to dotty-staging/scalatest that referenced this issue Oct 17, 2017
allanrenucci added a commit to dotty-staging/scalatest that referenced this issue Nov 1, 2017
cheeseng pushed a commit to cheeseng/scalatest that referenced this issue Nov 9, 2017
allanrenucci added a commit to dotty-staging/scalatest that referenced this issue Apr 18, 2018
@odersky
Copy link
Contributor

odersky commented Jun 24, 2018

I think there's no way to amke the cyclic error go away. So we need to work on the reporting side. test is neither overloaded nor recursive, so the error message should say something like:

"trying to follow acyclic reference when type-checking method test. Please add an explicit return type."

@Blaisorblade Blaisorblade self-assigned this Jun 29, 2018
Blaisorblade added a commit to dotty-staging/dotty that referenced this issue Jul 1, 2018
…better

- Record in CyclicReference if it's emitted during implicit search.
- Before checking if the error is on an implicit, check if we have an error
  during implicit search that happens while inferring a return type; that can
  happen whether the member we're typechecking is implicit or not, and needs the
  same cure.

This improves the error message, and also puts more effort into diagnosing the
cycle: we now use similar logic as for recursive/overloaded members to check
we're indeed dealing with a (potentially) recursive implicit.

Remaining `CyclicReferenceInvolvingImplicit` are unexpected and might involve
bugs, so make the error message and explanation more tentative, following
`CyclicReferenceInvolving`.
Blaisorblade added a commit to dotty-staging/dotty that referenced this issue Jul 7, 2018
…better

- Record in CyclicReference if it's emitted during implicit search.
- Before checking if the error is on an implicit, check if we have an error
  during implicit search that happens while inferring a return type; that can
  happen whether the member we're typechecking is implicit or not, and needs the
  same cure.
- Add ErrorMessagesTests as requested

This improves the error message, and also puts more effort into diagnosing the
cycle: we now use similar logic as for recursive/overloaded members to check
we're indeed dealing with a (potentially) recursive implicit.

Remaining `CyclicReferenceInvolvingImplicit` are unexpected and might involve
bugs, so make the error message and explanation more tentative, following
`CyclicReferenceInvolving`.
Blaisorblade added a commit to dotty-staging/dotty that referenced this issue Jul 24, 2018
…better

- Record in CyclicReference if it's emitted during implicit search.
- Before checking if the error is on an implicit, check if we have an error
  during implicit search that happens while inferring a return type; that can
  happen whether the member we're typechecking is implicit or not, and needs the
  same cure.
- Add ErrorMessagesTests as requested

This improves the error message, and also puts more effort into diagnosing the
cycle: we now use similar logic as for recursive/overloaded members to check
we're indeed dealing with a (potentially) recursive implicit.

Remaining `CyclicReferenceInvolvingImplicit` are unexpected and might involve
bugs, so make the error message and explanation more tentative, following
`CyclicReferenceInvolving`.

*However*, this does not yet handle mutually recursive methods in a reasonable
way.
Blaisorblade added a commit to dotty-staging/dotty that referenced this issue Jul 25, 2018
…better

- Record in CyclicReference if it's emitted during implicit search.
- Before checking if the error is on an implicit, check if we have an error
  during implicit search that happens while inferring a return type; that can
  happen whether the member we're typechecking is implicit or not, and needs the
  same cure.
- Add ErrorMessagesTests as requested

This improves the error message, and also puts more effort into diagnosing the
cycle: we now use similar logic as for recursive/overloaded members to check
we're indeed dealing with a (potentially) recursive implicit.

Remaining `CyclicReferenceInvolvingImplicit` are unexpected and might involve
bugs, so make the error message and explanation more tentative, following
`CyclicReferenceInvolving`.

*However*, this does not yet handle mutually recursive methods in a reasonable
way.
Blaisorblade added a commit to dotty-staging/dotty that referenced this issue Aug 9, 2018
…better

- Record in CyclicReference if it's emitted during implicit search.
- Before checking if the error is on an implicit, check if we have an error
  during implicit search that happens while inferring a return type; that can
  happen whether the member we're typechecking is implicit or not, and needs the
  same cure.
- Add ErrorMessagesTests as requested

This improves the error message, and also puts more effort into diagnosing the
cycle: we now use similar logic as for recursive/overloaded members to check
we're indeed dealing with a (potentially) recursive implicit.

Remaining `CyclicReferenceInvolvingImplicit` are unexpected and might involve
bugs, so make the error message and explanation more tentative, following
`CyclicReferenceInvolving`.

*However*, this does not yet handle mutually recursive methods in a reasonable
way.
@Blaisorblade
Copy link
Contributor

Fixed by #4729, closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:community build area:reporting Error reporting including formatting, implicit suggestions, etc itype:bug prio:low
Projects
None yet
Development

No branches or pull requests

4 participants