-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Explicit imports now shadow locally defined identifiers #6589
Conversation
348fe23
to
8784687
Compare
NB: two import fixes were still required, two others in tests pass after "Forgive import ambiguity". Those changes squashed in lead commit. |
This comment has been minimized.
This comment has been minimized.
/synch |
Even Seth doesn't know the password. Hey, how can settings be broken already? I'm only creating a Edit: rebased |
/synch goddamn it Scabot or I'll come over and put my foot right through your circuits |
"important" is clever but the previous PR had the benefit of |
Sample erroneous shadowing. The
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should split out the -Yimports
change into a separate PR.
The changes should come with tests.
Could you also summarize the changes in the commit messages?
What's the reason for changing the imports (the second commit)?
val pkg = sym.enclosingPackage.name | ||
!unitDefinesClassOrObject(pkg, sym.name) && !hasExplicitImport(body, pkg, sym.name) | ||
} | ||
if (!ok) report(sym) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was hoping for feedback on simple The imports in the few changed files are ambiguous. Very well, I'll split out The linked PR on 2.12 has full commit messages; I didn't expect it to get shut down. |
Also, the other PR includes the spec change for the precedence of "root" imports. As the message here says, this was a minimal forward port. |
I definitely like what I saw from
It confused me that the commit fixing imports comes after the change to imports handling. But now I see that's a case of https://help.github.com/articles/why-are-my-commits-in-the-wrong-order |
That just happened to me on another PR. I'll rebase and recreate commits here, adding what's missing from the 2.12 PR. Thanks for taking a look. I have high hopes for |
For example, ``` import p._ ; package p { S } ``` where S is both made available in p and also explicitly imported in enclosing scope. The usage S is ambiguous because it must not shadow the import.
Fixes the implementation of point 4. from SLS chapter 2: > Definitions made available by a package clause not in the > compilation unit where the reference occurs have lowest precedence. The implementation walks the context chain, but tries to be smart about how far it must walk, checking whether it has risen to an adequate depth. This check was previously broken for this case.
"Root" imports, implicitly supplied by the compiler, are lowest precedence.
If a definition and an import introduce an ambiguity, because the definition is at level 4 binding precedence, but imported symbol is just the definition, then ignore the import at that location. The pos test for ambiguous import was failing before.
Add words and counterexamples.
9a4bcc0
to
48fb060
Compare
specs2 diffs — this one was easier |
maybe due to scala/scala#6589 https://scala-ci.typesafe.com/job/scala-2.13.x-integrate-community-build/1302/consoleFull ``` [specs2-more] [error] /home/jenkins/workspace/scala-2.13.x-integrate-community-build/target-0.9.13/project-builds/specs2-more-db45127d55bd79c54d280645a81534fbc13e7a8b/form/src/test/scala/org/specs2/form/PropSpec.scala:62:31: too many arguments (2) for method apply: (key: String)(implicit evidence$1: sys.Prop.Creator[T])scala.sys.Prop[T] in object Prop [specs2-more] [error] val nameProp = Prop("name", "eric") [specs2-more] [error] ^ [specs2-more] [error] /home/jenkins/workspace/scala-2.13.x-integrate-community-build/target-0.9.13/project-builds/specs2-more-db45127d55bd79c54d280645a81534fbc13e7a8b/form/src/test/scala/org/specs2/form/PropSpec.scala:63:18: trait Prop is abstract; cannot be instantiated [specs2-more] [error] val noValues = new Prop("name") [specs2-more] [error] ^ [specs2-more] [error] /home/jenkins/workspace/scala-2.13.x-integrate-community-build/target-0.9.13/project-builds/specs2-more-db45127d55bd79c54d280645a81534fbc13e7a8b/form/src/test/scala/org/specs2/form/PropSpec.scala:64:25: type mismatch; [specs2-more] [error] found : Int(18) [specs2-more] [error] required: String [specs2-more] [error] val actualOnly = Prop(18) [specs2-more] [error] ^ [specs2-more] [error] /home/jenkins/workspace/scala-2.13.x-integrate-community-build/target-0.9.13/project-builds/specs2-more-db45127d55bd79c54d280645a81534fbc13e7a8b/form/src/test/scala/org/specs2/form/PropSpec.scala:65:22: trait Prop is abstract; cannot be instantiated [specs2-more] [error] val expectedOnly = new Prop("", Property(), Property(18)) [specs2-more] [error] ^ [specs2-more] [error] /home/jenkins/workspace/scala-2.13.x-integrate-community-build/target-0.9.13/project-builds/specs2-more-db45127d55bd79c54d280645a81534fbc13e7a8b/form/src/test/scala/org/specs2/form/PropSpec.scala:66:20: wrong number of type arguments for scala.sys.Prop, should be 1 [specs2-more] [error] val constrained: Prop[String, String] = Prop("name", "eric", (s1: String, s2: String) => s1 must contain(s2)) [specs2-more] [error] ^ [specs2-more] [error] /home/jenkins/workspace/scala-2.13.x-integrate-community-build/target-0.9.13/project-builds/specs2-more-db45127d55bd79c54d280645a81534fbc13e7a8b/form/src/test/scala/org/specs2/form/PropSpec.scala:66:56: too many arguments (3) for method apply: (key: String)(implicit evidence$1: sys.Prop.Creator[T])scala.sys.Prop[T] in object Prop [specs2-more] [error] val constrained: Prop[String, String] = Prop("name", "eric", (s1: String, s2: String) => s1 must contain(s2)) [specs2-more] [error] ^ [specs2-more] [error] /home/jenkins/workspace/scala-2.13.x-integrate-community-build/target-0.9.13/project-builds/specs2-more-db45127d55bd79c54d280645a81534fbc13e7a8b/form/src/test/scala/org/specs2/form/PropSpec.scala:67:34: too many arguments (3) for method apply: (key: String)(implicit evidence$1: sys.Prop.Creator[T])scala.sys.Prop[T] in object Prop [specs2-more] [error] val withMatcher = Prop("name", "eric", contain(_:String)) [specs2-more] [error] ^ [specs2-more] [error] /home/jenkins/workspace/scala-2.13.x-integrate-community-build/target-0.9.13/project-builds/specs2-more-db45127d55bd79c54d280645a81534fbc13e7a8b/form/src/test/scala/org/specs2/form/PropSpec.scala:75:20: too many arguments (3) for method apply: (key: String)(implicit evidence$1: sys.Prop.Creator[T])scala.sys.Prop[T] in object Prop [specs2-more] [error] e6 := Prop("", 1, be_>(0).mute).execute === Success("") [specs2-more] [error] ^ [specs2-more] [error] /home/jenkins/workspace/scala-2.13.x-integrate-community-build/target-0.9.13/project-builds/specs2-more-db45127d55bd79c54d280645a81534fbc13e7a8b/form/src/test/scala/org/specs2/form/PropSpec.scala:76:20: 3 more arguments than can be applied to method apply: (key: String)(implicit evidence$1: sys.Prop.Creator[T])scala.sys.Prop[T] in object Prop [specs2-more] [error] e7 := Prop("", 1, 2, be_>(0).mute).execute === Success("") [specs2-more] [error] ^ [specs2-more] [error] /home/jenkins/workspace/scala-2.13.x-integrate-community-build/target-0.9.13/project-builds/specs2-more-db45127d55bd79c54d280645a81534fbc13e7a8b/form/src/test/scala/org/specs2/form/PropSpec.scala:80:11: trait Prop is abstract; cannot be instantiated [specs2-more] [error] e1 := new Prop("name", expected = Property("fanny")).toString === "name: _ (expected: fanny)" [specs2-more] [error] ^ [specs2-more] [error] /home/jenkins/workspace/scala-2.13.x-integrate-community-build/target-0.9.13/project-builds/specs2-more-db45127d55bd79c54d280645a81534fbc13e7a8b/form/src/test/scala/org/specs2/form/PropSpec.scala:80:28: not found: value expected [specs2-more] [error] e1 := new Prop("name", expected = Property("fanny")).toString === "name: _ (expected: fanny)" [specs2-more] [error] ^ [specs2-more] [error] /home/jenkins/workspace/scala-2.13.x-integrate-community-build/target-0.9.13/project-builds/specs2-more-db45127d55bd79c54d280645a81534fbc13e7a8b/form/src/test/scala/org/specs2/form/PropSpec.scala:81:11: trait Prop is abstract; cannot be instantiated [specs2-more] [error] e2 := new Prop("name", actual = Property("eric")).toString === "name: eric" [specs2-more] [error] ^ [specs2-more] [error] /home/jenkins/workspace/scala-2.13.x-integrate-community-build/target-0.9.13/project-builds/specs2-more-db45127d55bd79c54d280645a81534fbc13e7a8b/form/src/test/scala/org/specs2/form/PropSpec.scala:81:28: not found: value actual [specs2-more] [error] e2 := new Prop("name", actual = Property("eric")).toString === "name: eric" [specs2-more] [error] ^ [specs2-more] [error] /home/jenkins/workspace/scala-2.13.x-integrate-community-build/target-0.9.13/project-builds/specs2-more-db45127d55bd79c54d280645a81534fbc13e7a8b/form/src/test/scala/org/specs2/form/PropSpec.scala:82:11: trait Prop is abstract; cannot be instantiated [specs2-more] [error] e3 := new Prop("name", Property("eric"), Property("eric")).toString === "name: eric" [specs2-more] [error] ^ [specs2-more] [error] /home/jenkins/workspace/scala-2.13.x-integrate-community-build/target-0.9.13/project-builds/specs2-more-db45127d55bd79c54d280645a81534fbc13e7a8b/form/src/test/scala/org/specs2/form/PropSpec.scala:86:24: too many arguments (2) for method apply: (key: String)(implicit evidence$1: sys.Prop.Creator[T])scala.sys.Prop[T] in object Prop [specs2-more] [error] e1 := Prop("name", "eric")("paolo").expected.toOption must_== Some("paolo") [specs2-more] [error] ^ [specs2-more] [error] 15 errors found [specs2-more] [error] (form / Test / compileIncremental) Compilation failed ```
maybe due to scala/scala#6589 https://scala-ci.typesafe.com/job/scala-2.13.x-integrate-community-build/1302/consoleFull ``` [specs2-more] [error] /home/jenkins/workspace/scala-2.13.x-integrate-community-build/target-0.9.13/project-builds/specs2-more-db45127d55bd79c54d280645a81534fbc13e7a8b/form/src/test/scala/org/specs2/form/PropSpec.scala:62:31: too many arguments (2) for method apply: (key: String)(implicit evidence$1: sys.Prop.Creator[T])scala.sys.Prop[T] in object Prop [specs2-more] [error] val nameProp = Prop("name", "eric") [specs2-more] [error] ^ [specs2-more] [error] /home/jenkins/workspace/scala-2.13.x-integrate-community-build/target-0.9.13/project-builds/specs2-more-db45127d55bd79c54d280645a81534fbc13e7a8b/form/src/test/scala/org/specs2/form/PropSpec.scala:63:18: trait Prop is abstract; cannot be instantiated [specs2-more] [error] val noValues = new Prop("name") [specs2-more] [error] ^ [specs2-more] [error] /home/jenkins/workspace/scala-2.13.x-integrate-community-build/target-0.9.13/project-builds/specs2-more-db45127d55bd79c54d280645a81534fbc13e7a8b/form/src/test/scala/org/specs2/form/PropSpec.scala:64:25: type mismatch; [specs2-more] [error] found : Int(18) [specs2-more] [error] required: String [specs2-more] [error] val actualOnly = Prop(18) [specs2-more] [error] ^ [specs2-more] [error] /home/jenkins/workspace/scala-2.13.x-integrate-community-build/target-0.9.13/project-builds/specs2-more-db45127d55bd79c54d280645a81534fbc13e7a8b/form/src/test/scala/org/specs2/form/PropSpec.scala:65:22: trait Prop is abstract; cannot be instantiated [specs2-more] [error] val expectedOnly = new Prop("", Property(), Property(18)) [specs2-more] [error] ^ [specs2-more] [error] /home/jenkins/workspace/scala-2.13.x-integrate-community-build/target-0.9.13/project-builds/specs2-more-db45127d55bd79c54d280645a81534fbc13e7a8b/form/src/test/scala/org/specs2/form/PropSpec.scala:66:20: wrong number of type arguments for scala.sys.Prop, should be 1 [specs2-more] [error] val constrained: Prop[String, String] = Prop("name", "eric", (s1: String, s2: String) => s1 must contain(s2)) [specs2-more] [error] ^ [specs2-more] [error] /home/jenkins/workspace/scala-2.13.x-integrate-community-build/target-0.9.13/project-builds/specs2-more-db45127d55bd79c54d280645a81534fbc13e7a8b/form/src/test/scala/org/specs2/form/PropSpec.scala:66:56: too many arguments (3) for method apply: (key: String)(implicit evidence$1: sys.Prop.Creator[T])scala.sys.Prop[T] in object Prop [specs2-more] [error] val constrained: Prop[String, String] = Prop("name", "eric", (s1: String, s2: String) => s1 must contain(s2)) [specs2-more] [error] ^ [specs2-more] [error] /home/jenkins/workspace/scala-2.13.x-integrate-community-build/target-0.9.13/project-builds/specs2-more-db45127d55bd79c54d280645a81534fbc13e7a8b/form/src/test/scala/org/specs2/form/PropSpec.scala:67:34: too many arguments (3) for method apply: (key: String)(implicit evidence$1: sys.Prop.Creator[T])scala.sys.Prop[T] in object Prop [specs2-more] [error] val withMatcher = Prop("name", "eric", contain(_:String)) [specs2-more] [error] ^ [specs2-more] [error] /home/jenkins/workspace/scala-2.13.x-integrate-community-build/target-0.9.13/project-builds/specs2-more-db45127d55bd79c54d280645a81534fbc13e7a8b/form/src/test/scala/org/specs2/form/PropSpec.scala:75:20: too many arguments (3) for method apply: (key: String)(implicit evidence$1: sys.Prop.Creator[T])scala.sys.Prop[T] in object Prop [specs2-more] [error] e6 := Prop("", 1, be_>(0).mute).execute === Success("") [specs2-more] [error] ^ [specs2-more] [error] /home/jenkins/workspace/scala-2.13.x-integrate-community-build/target-0.9.13/project-builds/specs2-more-db45127d55bd79c54d280645a81534fbc13e7a8b/form/src/test/scala/org/specs2/form/PropSpec.scala:76:20: 3 more arguments than can be applied to method apply: (key: String)(implicit evidence$1: sys.Prop.Creator[T])scala.sys.Prop[T] in object Prop [specs2-more] [error] e7 := Prop("", 1, 2, be_>(0).mute).execute === Success("") [specs2-more] [error] ^ [specs2-more] [error] /home/jenkins/workspace/scala-2.13.x-integrate-community-build/target-0.9.13/project-builds/specs2-more-db45127d55bd79c54d280645a81534fbc13e7a8b/form/src/test/scala/org/specs2/form/PropSpec.scala:80:11: trait Prop is abstract; cannot be instantiated [specs2-more] [error] e1 := new Prop("name", expected = Property("fanny")).toString === "name: _ (expected: fanny)" [specs2-more] [error] ^ [specs2-more] [error] /home/jenkins/workspace/scala-2.13.x-integrate-community-build/target-0.9.13/project-builds/specs2-more-db45127d55bd79c54d280645a81534fbc13e7a8b/form/src/test/scala/org/specs2/form/PropSpec.scala:80:28: not found: value expected [specs2-more] [error] e1 := new Prop("name", expected = Property("fanny")).toString === "name: _ (expected: fanny)" [specs2-more] [error] ^ [specs2-more] [error] /home/jenkins/workspace/scala-2.13.x-integrate-community-build/target-0.9.13/project-builds/specs2-more-db45127d55bd79c54d280645a81534fbc13e7a8b/form/src/test/scala/org/specs2/form/PropSpec.scala:81:11: trait Prop is abstract; cannot be instantiated [specs2-more] [error] e2 := new Prop("name", actual = Property("eric")).toString === "name: eric" [specs2-more] [error] ^ [specs2-more] [error] /home/jenkins/workspace/scala-2.13.x-integrate-community-build/target-0.9.13/project-builds/specs2-more-db45127d55bd79c54d280645a81534fbc13e7a8b/form/src/test/scala/org/specs2/form/PropSpec.scala:81:28: not found: value actual [specs2-more] [error] e2 := new Prop("name", actual = Property("eric")).toString === "name: eric" [specs2-more] [error] ^ [specs2-more] [error] /home/jenkins/workspace/scala-2.13.x-integrate-community-build/target-0.9.13/project-builds/specs2-more-db45127d55bd79c54d280645a81534fbc13e7a8b/form/src/test/scala/org/specs2/form/PropSpec.scala:82:11: trait Prop is abstract; cannot be instantiated [specs2-more] [error] e3 := new Prop("name", Property("eric"), Property("eric")).toString === "name: eric" [specs2-more] [error] ^ [specs2-more] [error] /home/jenkins/workspace/scala-2.13.x-integrate-community-build/target-0.9.13/project-builds/specs2-more-db45127d55bd79c54d280645a81534fbc13e7a8b/form/src/test/scala/org/specs2/form/PropSpec.scala:86:24: too many arguments (2) for method apply: (key: String)(implicit evidence$1: sys.Prop.Creator[T])scala.sys.Prop[T] in object Prop [specs2-more] [error] e1 := Prop("name", "eric")("paolo").expected.toOption must_== Some("paolo") [specs2-more] [error] ^ [specs2-more] [error] 15 errors found [specs2-more] [error] (form / Test / compileIncremental) Compilation failed ```
Scala 2.13 support was added to build via #5454. This PR adjusts the code so that it compiles with 2.11, 2.12 and 2.13. Changes: * Add `scala-collection-compat` dependency. * Import `scala.collection.Seq` in a number of places for consistent behavior between Scala 2.11, 2.12 and 2.13. * Remove wildcard imports that were causing the Java classes to have priority over the Scala ones, related Scala issue: scala/scala#6589. * Replace parallel collection usage with `Future`. The former is no longer included by default in the standard library. * Replace val _: Unit workaround with one that is more concise and works with Scala 2.13 * Replace `filterKeys` with `filter` when we expect a `Map`. `filterKeys` returns a view that doesn't implement the `Map` trait in Scala 2.13. * Replace `mapValues` with `map` or add a `toMap` as an additional transformation when we expect a `Map`. `mapValues` returns a view that doesn't implement the `Map` trait in Scala 2.13. * Replace `breakOut` with `iterator` and `to`, `breakOut` was removed in Scala 2.13. * Replace to() with toMap, toIndexedSeq and toSet * Replace `mutable.Buffer.--` with `filterNot`. * ControlException is an abstract class in Scala 2.13. * Variable arguments can only receive arrays or immutable.Seq in Scala 2.13. * Use `Factory` instead of `CanBuildFrom` in DecodeJson. `CanBuildFrom` behaves a bit differently in Scala 2.13 and it's been deprecated. `Factory` has the behavior we need and it's available via the compat library. * Fix failing tests due to behavior change in Scala 2.13, "Map.values.map is not strict in Scala 2.13" (scala/bug#11589). * Use Java collections instead of Scala ones in StreamResetter (a Java class). * Adjust CheckpointFile.write to take an `Iterable` instead of `Seq` to avoid unnecessary collection copies. * Fix DelayedElectLeader to use a Map instead of Set and avoid `to` call that doesn't work in Scala 2.13. * Use unordered map for mapping in SimpleAclAuthorizer, mapping of ordered maps require an `Ordering` in Scala 2.13 for safety reasons. * Adapt `ConsumerGroupCommand` to compile with Scala 2.13. * CoreUtils.min takes an `Iterable` instead of `TraversableOnce`, the latter does not exist in Scala 2.13. * Replace `Unit` with `()` in a couple places. Scala 2.13 is stricter when it expects a value instead of a type. * Fix bug in CustomQuotaCallbackTest where we did not necessarily set `partitionRatio` correctly, `forall` can terminate early. * Add a couple of spotbugs exclusions that are needed by code generated by Scala 2.13 * Remove unused variables, simplify some code and remove procedure syntax in a few places. * Remove unused `CoreUtils.JSONEscapeString`. Reviewers: Manikumar Reddy <manikumar.reddy@gmail.com>, José Armando García Sancio <jsancio@users.noreply.github.com>
There is now some further discussion and justification at scala/bug#11593 |
Scala -> 2.13 (previously 2.12) Play -> 2.8 (2.6) SBT -> 1.5.6 (0.13) This was a bit of a gigantic upgrade due to dependency binary incompatibilities (dependency coupling) and general breaking changes. Hopefully in future we can do smaller and more frequent updates. To break down the changes: 1. Removal of some niche dependencies The list is: diffson-play-json, scala-ssh, henkan-convert. These were either unused or used only a little. 2. .mapValues -> .view.mapValues(...).toMap https://docs.scala-lang.org/overviews/core/collections-migration-213.html#what-are-the-breaking-changes 3. other Scala 2.12 and 2.13 changes * .par now requires a special import * Seq is now core.immutable.Seq * import precendence and shadowing seems to have changed (see: scala/scala#6589), which caused issues as task and deployment_types packages share many names * requirement to drop parens when a method (typically controller method) was defined without them * etc. 4. library breaking changes For example, in the Guardian's own Play Secret and GoogleAuth libraries, or in the Boostrap ('b3') library, especially in how forms are defined. 5. SBT changes The deprecation of 'in' for '/' instead.
Scala -> 2.13 (previously 2.12) Play -> 2.8 (2.6) SBT -> 1.5.6 (0.13) This was a bit of a gigantic upgrade due to dependency binary incompatibilities (dependency coupling) and general breaking changes. Hopefully in future we can do smaller and more frequent updates. To break down the changes: 1. Removal of some niche dependencies The list is: diffson-play-json, scala-ssh, henkan-convert. These were either unused or used only a little. 2. .mapValues -> .view.mapValues(...).toMap https://docs.scala-lang.org/overviews/core/collections-migration-213.html#what-are-the-breaking-changes 3. other Scala 2.12 and 2.13 changes * .par now requires a special import * Seq is now core.immutable.Seq * import precendence and shadowing seems to have changed (see: scala/scala#6589), which caused issues as task and deployment_types packages share many names * requirement to drop parens when a method (typically controller method) was defined without them * etc. 4. library breaking changes For example, in the Guardian's own Play Secret and GoogleAuth libraries, or in the Boostrap ('b3') library, especially in how forms are defined. 5. SBT changes The deprecation of 'in' for '/' instead.
Original title: "Import shadows def in other unit, per spec"
Forward port of #5339 .
Fixes scala/bug#2458
Fixes scala/bug#9552