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

type cannot be inferred if companion object has more than 1 same-name fields with the case class #9021

Closed
scabug opened this issue Nov 30, 2014 · 2 comments
Assignees

Comments

@scabug
Copy link

scabug commented Nov 30, 2014

case class Test(a: Int, b: String)
object Test {
  val test = Test(a = 10, b = "123")
  def a = test.a
  def b = test.b
}

failed but

case class Test(a: Int, b: String)
object Test {
  val test = Test(a = 10, b = "123")
  def a = test.a
}

passed.

@scabug
Copy link
Author

scabug commented Nov 30, 2014

Imported From: https://issues.scala-lang.org/browse/SI-9021?orig=1
Reporter: centaur
Affected Versions: 2.11.4
Duplicates #5044

@scabug
Copy link
Author

scabug commented Dec 3, 2014

@retronym said:
This is a known limitation of the way that named arguments are typechecked (#5044). The compiler outputs a diagnostic that suggests a solution: annotate the type of t or of a.

scalac-hash v2.11.4 sandbox/test.scala
sandbox/test.scala:5: error: recursive value test needs type
  def b = test.b
          ^
sandbox/test.scala:3: warning: type-checking the invocation of method apply checks if the named argument expression 'b = ...' 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 b.
  val test = Test(a = 10, b = "123")
                            ^
sandbox/test.scala:3: warning: type-checking the invocation of method apply checks if the named argument expression 'a = ...' 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 a.
  val test = Test(a = 10, b = "123")
                    ^
two warnings found
one error found

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

2 participants