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

Strange compiler bug caused by some sort of misidentified name conflict #7381

Closed
scabug opened this issue Apr 17, 2013 · 8 comments
Closed
Assignees

Comments

@scabug
Copy link

scabug commented Apr 17, 2013

object ConfigExampleApp extends App {
  case class Config(name: String = null)
  val parser = new scopt.immutable.OptionParser[Config]("a", "b") {
    def options = Seq(
      arg("name", "the name of something") {
        (value, conf) => conf.copy(name = value)
      }
    )
  }
  val config = parser.parse(args, new Config).get
  val name = config.name
}

you will need a jar of https://github.com/jstrachan/scopt to resolve that dependency.

In this case, i get an error "no value value" on the (name = value) section in the middle. It turns out to be caused by the overlap of the name of "val name" and "Config.name". If I rename either of those, the code compiles.

@scabug
Copy link
Author

scabug commented Apr 17, 2013

Imported From: https://issues.scala-lang.org/browse/SI-7381?orig=1
Reporter: Mike Schrag (mschrag)
Affected Versions: 2.10.0
Duplicates #5044
Attachments:

@scabug
Copy link
Author

scabug commented Apr 17, 2013

Mike Schrag (mschrag) said:
whoops, that should be https://github.com/scopt/scopt . i sent the older link inadvertently.

@scabug
Copy link
Author

scabug commented Apr 17, 2013

Mike Schrag (mschrag) said:
adding the same jar I'm using

@scabug
Copy link
Author

scabug commented Apr 17, 2013

@paulp said:
Have you tried and failed to reproduce this without the dependency? It seems unlikely this is specific to scopt.

@scabug
Copy link
Author

scabug commented Apr 17, 2013

Mike Schrag (mschrag) said:
It's almost certainly not scoot-specific, but isolating it was becoming tricky. The error is inside of the inner function, but it's caused by the naming outside the function. If I completely remove the entire middle scopt section, it works. I tried a slightly larger example and it worked as well, so I figured I'd go ahead and just file it with the dependency. I figured you guys might be able to more quickly see the problem outright compared to me trying to narrow the test case further.

@scabug
Copy link
Author

scabug commented Apr 17, 2013

@paulp said:
Duplicate of #5044.

If you compile with 2.10.1 instead of 2.10.0, you will get a better error message.

./7381.scala:9: error: not found: value value
        (value, conf) => conf.copy(name = value)
                                          ^
./7381.scala:9: warning: type-checking the invocation of method copy checks if the named argument expression 'name = ...' 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 name.
        (value, conf) => conf.copy(name = value)
                                        ^
one warning found
one error found

@scabug
Copy link
Author

scabug commented Apr 17, 2013

@paulp said:
And indeed if I do as it suggests, "val name: String = config.name", it compiles.

@scabug scabug closed this as completed Apr 17, 2013
@scabug
Copy link
Author

scabug commented Apr 17, 2013

Mike Schrag (mschrag) said:
Sadly, I just finished a more narrow test case of it, too. Thanks, Paul.

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