8000 Remove logic to check if a named arg could be an assignment (and enable `-Xsource:2.13` by default) by lrytz · Pull Request #6092 · scala/scala · GitHub
[go: up one dir, main page]

Skip to content

Remove logic to check if a named arg could be an assignment (and enable -Xsource:2.13 by default) #6092

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

Merged
merged 6 commits into from
Dec 1, 2017

Conversation

lrytz
Copy link
Member
@lrytz lrytz commented Sep 21, 2017

An x = e expression in parameter position is now a named argument,
syntactically, unconditionally.

Fixes scala/scala-dev#426

Issue a deprecation warning when an assignment expression (`x = e`)
in a parameter position is treated as an assignment, not a named
argument.

In 2.13 this will be an error, `f(x = e)` will be restricted to
named arguments and never be treated as an assignment to `x`.

The 2.13 behavior is available under `-Xsource:2.13`

See scala/scala-dev#426
@scala-jenkins scala-jenkins added this to the 2.13.0-M3 milestone Sep 21, 2017
@lrytz
Copy link
Member Author
lrytz commented Sep 21, 2017

Hehe, our current 2.13.x branch doesn't compile with -Xsource:2.13

[error] /home/jenkins/workspace/scala-2.13.x-validate-test/src/library/scala/sys/process/BasicIO.scala:165: type mismatch;
[error]  found   : String
[error]  required: () => String
[error]     try processLinesFully(processLine)(reader.readLine)
[error]                                               ^

@@ -133,7 +135,7 @@ trait ScalaSettings extends AbsScalaSettings
val sourceReader = StringSetting ("-Xsource-reader", "classname", "Specify a custom method for reading source files.", "")
val reporter = StringSetting ("-Xreporter", "classname", "Specify a custom reporter for compiler messages.", "scala.tools.nsc.reporters.ConsoleReporter")
val strictInference = BooleanSetting ("-Xstrict-inference", "Don't infer known-unsound types")
val source = ScalaVersionSetting ("-Xsource", "version", "Treat compiler input as Scala source for the specified version, see scala/bug#8126.", initial = ScalaVersion("2.12"))
val source = ScalaVersionSetting ("-Xsource", "version", "Treat compiler input as Scala source for the specified version, see scala/bug#8126.", initial = ScalaVersion("2.13"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch!

* Marks a TypeError that was constructed from a CyclicReference (under silent). This was used
* up to 2.12 to identify cyclic references when type checking a named argument as if it were an
* assignment (to figure out if the expression was a valid assignment, a4a892fb01). Since 2.13 we
* could use a normal NormalTypeError, but I'll leave it in for now, it might come in handy.
*/
class NormalTypeErrorFromCyclicReference(underlyingTree: Tree, errMsg: String)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm always weary of leaving unused stuff in, because some future dev may misunderstand its purpose and wreak havoc with it :-)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I'm happy to remove it.

@lrytz lrytz force-pushed the syntacticNamedArgs-213 branch 2 times, most recently from 2f07a7f to c21c5c5 Compare September 22, 2017 06:14
Remove `@elidable` from abstract methods in tests, improve the error
message. Also improve the scaladoc on `@elidable`.
@lrytz lrytz force-pushed the syntacticNamedArgs-213 branch from c21c5c5 to f1e5d65 Compare Septemb 8000 er 22, 2017 09:52
@@ -0,0 +1,6 @@
object Test extends App {
def foo(): () => String = () => "hi there"
val f: () => Any = foo
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that in 2.13 (-Xsource:2.13) this compiles without a warning, foo is applied to the empty parameter list.

In 2.12, eta-expansion comes in before, and it compiles with a deprecation warning:

➜  sandbox git:(syntacticNamedArgs-213) scalac Test.scala -deprecation
Test.scala:3: warning: Eta-expansion of zero-argument method values is deprecated. Did you intend to write Test.this.foo()?
  val f: () => Any = foo
                     ^
one warning found

So the program compiles in both versions, but differently.

Nullary methods are no longer eta-expanded.
Assignments in paramter position need to be wrapped in brackets.
@lrytz lrytz force-pushed the syntacticNamedArgs-213 branch from f1e5d65 to 03becd5 Compare September 22, 2017 10:02
Adjust tests as necessary.

Remove run test for t10097, it produces a compiler error under
Xsource:2.13. This is tested in a neg test.
@lrytz lrytz force-pushed the syntacticNamedArgs-213 branch from 03becd5 to b984e99 Compare September 22, 2017 11:55
An `x = e` expression in parameter position is now a named argument,
syntactically, unconditionally.

Fixes scala/scala-dev#426
@adriaanm adriaanm merged commit 8272151 into scala:2.13.x Dec 1, 2017
@adriaanm
Copy link
Contributor
adriaanm commented Dec 1, 2017

Sorry for the delay, Lukas.

@lrytz
Copy link
Member Author
lrytz commented Dec 1, 2017

This merge broke the build, as noted in #6143 (comment)

These are most likely the relevant commits that went into 2.13.x after this PRs parent:

lrytz added a commit to lrytz/scala that referenced this pull request Dec 1, 2017
In scala#6092, `-Xsource:2.13` was enabled by default. Between this PRs
parent and current 2.13.x, there were some changes that depended on
this flag (scala#5983, scala#6069).
hrhino added a commit to hrhino/scala that referenced this pull request Jan 16, 2018
- scala/bug#5638 was fixed by something farther back than I can build.
- scala/bug#8348 was fixed by scala#5251.
- scala/bug#9291 was fixed by scala#6092.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-notes worth highlighting in next release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0