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

Unexpected "recursive value needs type" error #5091

Closed
scabug opened this issue Oct 19, 2011 · 18 comments
Closed

Unexpected "recursive value needs type" error #5091

scabug opened this issue Oct 19, 2011 · 18 comments

Comments

@scabug
Copy link

scabug commented Oct 19, 2011

With scala-2.10.0.r25850-b20111019023417, compiling:

// RecursiveValueNeedsType.scala
object RecursiveValueNeedsType {

  def foo(param: String) = 42
  def bar(n: Int) = 42

  {
    val xxx = foo(param = null)
    val param = bar(xxx)
  }
  
}

Gives the error:

RecursiveValueNeedsType.scala:8: error: recursive value xxx needs type
    val param = bar(xxx)
@scabug
Copy link
Author

scabug commented Oct 19, 2011

Imported From: https://issues.scala-lang.org/browse/SI-5091?orig=1
Reporter: Matt Russell (mattrussell)
See #8342, #5044, #6051

@scabug
Copy link
Author

scabug commented Feb 5, 2012

@scabug
Copy link
Author

scabug commented Jul 12, 2012

@lrytz said (edited on Jul 12, 2012 7:45:30 AM UTC):
very similar symptom in #6051

@scabug
Copy link
Author

scabug commented Sep 18, 2014

Przemek Sokół (falconepl) said:
If you wrap such a code with a ScalaTest test, instead of a type checker confusion you get a compiler error:

    [error] Unknown type: <error>, <error> [class scala.reflect.internal.Types$ErrorType$, class scala.reflect.internal.Types$ErrorType$] TypeRef? false
    [trace] Stack trace suppressed: run last test:compile for the full output.
    [error] (test:compile) scala.reflect.internal.FatalError: Unknown type: <error>, <error> [class scala.reflect.internal.Types$ErrorType$, class scala.reflect.internal.Types$ErrorType$] TypeRef? false

You can find exemplary code here.

@scabug
Copy link
Author

scabug commented Oct 10, 2014

@retronym said:
This gives a pretty reasonable error message these days:

qscalac test/pending/pos/t5091.scala
test/pending/pos/t5091.scala:8: error: recursive value xxx needs type
    val param = bar(xxx)
                    ^
test/pending/pos/t5091.scala:7: warning: type-checking the invocation of method foo checks if the named argument expression 'param = ...' is a valid assignment
in the current scope. The resulting type inference error (see above) can be fixed by providing an explicit type in the local definition for param.
    val xxx = foo(param = null)
                        ^
one warning found
one error found

@scabug
Copy link
Author

scabug commented Oct 10, 2014

@retronym said:
I'm planning to close this one with that error message in a neg test: scala/scala#4044

@scabug
Copy link
Author

scabug commented Nov 21, 2014

Christopher (metch) said:
To fix this issue with the current Scala version (<= 2.11.4), the type of param must be added: val param: Int = bar(xxx).
The above code example will compile without warning or error in 2.11.5, right ?

@scabug
Copy link
Author

scabug commented Nov 21, 2014

@som-snytt said:
No, Jason reports the messages above. For the record, the message strings are very long (more than twitter length).

@scabug
Copy link
Author

scabug commented Mar 19, 2015

Ivan Suhinin (suhinini) said:
Guys this is still reproducible in Scala 2.11.6. Please check out sample project: https://github.com/suhinini/SI-5091-Scala-2-11-6-Reopen

@scabug
Copy link
Author

scabug commented Mar 19, 2015

Przemek Sokół (falconepl) said:
@[~suhinini]
Actually, when I compile your project in SBT, this is what I get:

[error] /home/.../SI-5091-Scala-2-11-6-Reopen/Test.scala:6: recursive value x needs type
[error]     val id = x + 1
[error]              ^
[error] one error found
[error] (compile:compile) Compilation failed

@scabug
Copy link
Author

scabug commented Mar 19, 2015

Ivan Suhinin (suhinini) said:
So my recursive value x needs type is different from bug's recursive value needs type? Sorry if it is a different bug, just seems exactly like this one.

@scabug
Copy link
Author

scabug commented Mar 19, 2015

@retronym said:
Looks like a SBT bug, scalac outputs a diagnostic warning for that code, but this is swallowed by SBT in favour of the compile error.

I've lodged this as sbt/sbt#1928

@scabug
Copy link
Author

scabug commented Mar 19, 2015

Przemek Sokół (falconepl) said (edited on Mar 19, 2015 7:11:33 PM UTC):
@[~suhinini]
No, it's not. They are the same. But, as far as I understand, this issue is closed as it has been concluded that such a message is enough for this wierd typechecking cycle. See other comments, especially those by @retronym: {quote}I'm planning to close this one with that error message in a neg test{quote}.
Update:
OK, as Jason pointed out, it's that additional warning (to the compile error) that is swallowed by SBT.

@scabug
Copy link
Author

scabug commented Mar 20, 2015

Ivan Suhinin (suhinini) said:
Thanks guys, now I get the resolution of this. Just spent some time yesterday trying to understand what's going on, wasn't clear without warning.

@scabug
Copy link
Author

scabug commented Jul 22, 2015

Netta Doron (nettad) said:
I have a service running on scala version 2.11.7 and I'm still experiencing this issue.
case class Foo(id: UUID)
class FooTest extends org.specs2.mutable.SpecificationWithJUnit {
"this should compile" in
{ val foo = Foo(id = UUID.randomUUID) val id = foo.id true must beTrue }
}
generates the error recursive value foo needs type.
val id = foo.id

@scabug
Copy link
Author

scabug commented Jul 22, 2015

@lrytz said:
related to #8342. we plan to dis-ambiguate the foo(a = x) syntax so that it can only mean a named argument, not an assignment to a.

@aaabramov
Copy link

@scala scala deleted a comment from scabug Aug 2, 2018
@scala scala deleted a comment from scabug Aug 2, 2018
@xuwei-k
Copy link

xuwei-k commented Aug 12, 2018

fixed since Scala 2.13.0-M4

scala/scala@a992c83#diff-3828abb025ee93aa4f0b1d654200e5c9

@xuwei-k xuwei-k closed this as completed Aug 12, 2018
@SethTisue SethTisue removed this from the Backlog milestone Aug 12, 2018
@SethTisue SethTisue added this to the 2.13.0-M4 milestone Aug 12, 2018
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

5 participants