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

Error message not helpful when val definition contains extra '()' #6564

Closed
scabug opened this issue Oct 24, 2012 · 4 comments
Closed

Error message not helpful when val definition contains extra '()' #6564

scabug opened this issue Oct 24, 2012 · 4 comments
Labels
enhancement fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/) usability

Comments

@scabug
Copy link

scabug commented Oct 24, 2012

If a val definition contains an extra set of parenthesis, like if not correctly transforming a def into a val, the error reported by the compiler is not really helpful.

$ scalac test.scala 
test.scala:5: error: not found: value a
  val a(): String = ""
      ^
one error found

It would be better if the error was something like: expected ':' or '=', found '('

@scabug
Copy link
Author

scabug commented Oct 24, 2012

Imported From: https://issues.scala-lang.org/browse/SI-6564?orig=1
Reporter: @skyluc
Affected Versions: 2.9.2, 2.10.0-RC1

@scabug
Copy link
Author

scabug commented Oct 24, 2012

@retronym said:
Problem is that is is valid syntactically.

scala> object a { def unapply(a: Any): Boolean = true }
defined module a

scala> { val a(): String = ""; 0 }
res3: Int = 0

scala> cm.universe.reify { val a(): String = "" }
res18: cm.universe.Expr[Unit] =
Expr[Unit]({
  <synthetic> private[this] val x$1 = ("": @unchecked: String) match {
    case a() => ()
  };
  ()
})

scala> val cm = reflect.runtime.currentMirror
cm: reflect.runtime.universe.Mirror = JavaMirror with ...

scala> cm.universe.showRaw(res18)
res19: String =
Expr[Unit]({
  <synthetic> private[this] val x$1 = ("": @unchecked: String) match {
    case a() => ()
  };
  ()
})

scala> cm.universe.showRaw(res18.tree)
res20: String = Block(List(ValDef(Modifiers(PRIVATE | LOCAL | SYNTHETIC), newTermName("x$1"), TypeTree(), Match(Typed(Annotated(Apply(Select(New(Ident(scala.unchecked)), nme.CONSTRUCTOR), List()), Literal(Constant(""))), Ident(newTypeName("String"))), List(CaseDef(Apply(Select(Select(Select(Select(Ident($line34), newTermName("$read")), newTermName("$iw")), newTermName("$iw")), newTermName("a")), List()), EmptyTree, Literal(Constant(()))))))), Literal(Constant(())))

@scabug
Copy link
Author

scabug commented Jul 10, 2013

@adriaanm said:
Unassigning as milestone deadline was reached.

@som-snytt
Copy link

som-snytt commented Nov 15, 2019

Punting this in favor of actual correctness bugs in this area. Possible umbrella issue: #11800

The use case is switching def to val.

This case is probably a scalafix lint.

@SethTisue SethTisue removed this from the Backlog milestone Nov 15, 2019
@som-snytt som-snytt closed this as not planned Won't fix, can't repro, duplicate, stale Oct 11, 2023
@som-snytt som-snytt added the fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/) label Oct 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/) usability
Projects
None yet
Development

No branches or pull requests

3 participants