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

Sbt can't compile due to shadowing of Range class #8262

Closed
scabug opened this issue Feb 11, 2014 · 12 comments
Closed

Sbt can't compile due to shadowing of Range class #8262

scabug opened this issue Feb 11, 2014 · 12 comments
Assignees
Labels
Milestone

Comments

@scabug
Copy link

scabug commented Feb 11, 2014

I just tried building sbt with Scala 2.11.0-M8 and I got:

[error] /Users/grek/scala/xsbt/main/actions/src/main/scala/sbt/compiler/Eval.scala:362: value toArray is not a member of Eval.this.global.Range
[error] 			defs += fragmentUnit(defString, range.toArray)
[error] 			                                      ^
[error] /Users/grek/scala/xsbt/main/actions/src/main/scala/sbt/compiler/Eval.scala:364: type mismatch;
[error]  found   : Eval.this.global.Range
[error]  required: scala.collection.TraversableOnce[Int]
[error] 			lines ++= range
[error] 			          ^
[error] /Users/grek/scala/xsbt/main/actions/src/main/scala/sbt/compiler/Eval.scala:366: value end is not a member of Eval.this.global.Range
[error] 			lines ++= (range.end :: range.end :: Nil)
[error] 			                 ^
[error] /Users/grek/scala/xsbt/main/actions/src/main/scala/sbt/compiler/Eval.scala:366: value end is not a member of Eval.this.global.Range
[error] 			lines ++= (range.end :: range.end :: Nil)
[error] 			                              ^
[error] four errors found

I've been scratching my head for a while but then it became clear what happened. The code in Eval.scala refers to scala.Range (without any explicit import). Now, for reason I didn't identify yet there's Range class mixed into Global name space. Compare:

// Scala 2.10.2
scala> val globalTpe = typeOf[Global]
globalTpe: $r.intp.global.Type = scala.tools.nsc.Global

scala> globalTpe.member("Range": TypeName)
res5: $r.intp.global.Symbol = <none>

// Scala 2.11.0-M8
scala> val globalTpe = typeOf[Global]
globalTpe: $r.intp.global.Type = scala.tools.nsc.Global

scala> globalTpe.member("Range": TypeName)
res12: $r.intp.global.Symbol = class Range

scala> res12.fullName
res13: String = scala.reflect.internal.Positions.Range

That class shadows (through globa._ import) the one previously used.

@scabug
Copy link
Author

scabug commented Feb 11, 2014

Imported From: https://issues.scala-lang.org/browse/SI-8262?orig=1
Reporter: @gkossakowski
Affected Versions: 2.11.0-M8

@scabug
Copy link
Author

scabug commented Feb 11, 2014

@gkossakowski said:
The trivial fix on sbt-side is to replace {{import global._}} with {{import global.{Range => _, _}}} but then we run into SI-8263.

@scabug
Copy link
Author

scabug commented Feb 11, 2014

@retronym said:
I hit a similar problem with Slick: https://github.com/retronym/slick/compare/tmp;2.11-compat-2?expand=1#diff-ae7c9eb3f64697f672b969a28c06e892R122

We need to figure out which change in Scala is responsible.

@scabug
Copy link
Author

scabug commented Feb 11, 2014

@retronym said:
I just confirmed that there is no change in compiler behaviour for this one, it is just adding a name to the Global namespace in scala/scala@c434138

@scabug
Copy link
Author

scabug commented Feb 11, 2014

@retronym said:
That seems obvious enough from your bug description, but the unexplained change in Slick had me a bit worried.

@scabug
Copy link
Author

scabug commented Feb 11, 2014

@gkossakowski said:
I can't spot the connection between the change in Slick you linked to and this ticket.

Do we want to rename the class or refactor the code so it's not private anymore?

If it's true that c4341385629bd114b61c55103f1d83f26dce22f9 introduced regression how's possible that I report it 11 months later? Could it be that nobody tried to compile or never got to compiling sbt's main subproject during last 11 months?

@scabug
Copy link
Author

scabug commented Feb 11, 2014

@retronym said:
I also got a new error due to shadowing in Slick when compiling with master today. I haven't minimized it yet.

I thought these nightly builds of SBT with 2.11 should have caught this:

https://jenkins-dbuild.typesafe.com:8499/job/sbt-nightly-for-ide-on-scala-2.11.x/215/consoleFull

@scabug
Copy link
Author

scabug commented Feb 11, 2014

@retronym said:
I can't actually reproduce the problem as I don't know where to find releases of sbinary for M8.

I used this minimization:

object Test {
  val g: scala.tools.nsc.Global = ???

  import g._

  def foo(r: Range) = r: scala.Range
}

Which starts giving the same error as your report when Range was added to a supertype of Global.

But something still doesn't add up.

@scabug
Copy link
Author

scabug commented Feb 11, 2014

@gkossakowski said:
I built sbinary against M8 locally. I summed up steps necessary to reproduce here: https://gist.github.com/gkossakowski/8940448

When it comes to nightly builds, this one build only subset of Sbt that constitutes incremental compiler (and it's dependencies), see the following log entry:

[info] The following subprojects will be built in project sbt: control, io, process, interface, logging, api, relation, classfile, launcher-interface, classpath, incremental-compiler, persist, launcher, compiler-interface, compile, compiler-integration

See also the dbuild definition:

{
        name:   "sbt",
        uri:    "git://github.com/sbt/sbt.git#0.13"
        extra: {
          sbt-version: "0.13.0",
          projects: ["compiler-interface",
                     "classpath","logging","io","control","classfile",
                     "process","relation","interface","persist","api",
                     "compiler-integration","incremental-compiler","compile","launcher-interface"
                    ],
          run-tests: false,
          commands: [ "set every Util.includeTestDependencies := false" // Without this, we have to build specs2
                    ]
        }
      }

In retrospect, it looks like the choice of names for jenkins jobs and configuration files was a bit unfortunate.

@scabug scabug closed this as completed Feb 12, 2014
@scabug
Copy link
Author

scabug commented Feb 12, 2014

@retronym said:
Closing as not-a-bug. I've made SBT compatible here: sbt/sbt#1113

@scabug
Copy link
Author

scabug commented Feb 12, 2014

@retronym said:
I've also analysed the change I observed in Slick. The new behaviour is correct, and I've submitted a test to lock it down: scala/scala#3515

@scabug
Copy link
Author

scabug commented Feb 12, 2014

@adriaanm said (edited on Feb 12, 2014 7:16:46 PM UTC):
[EDIT: I was accidentally looking at the empty commits tab and thought there were no comments when I wrote this] That Range class was introduced 12 months ago in #2197. Have we not built this part of sbt on master since then?

@scabug scabug added the blocker label Apr 7, 2017
@scabug scabug added this to the 2.11.0-RC1 milestone Apr 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants