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

implicit import of scala.Predef. Spec differs from implementation #7672

Closed
scabug opened this issue Jul 17, 2013 · 3 comments
Closed

implicit import of scala.Predef. Spec differs from implementation #7672

scabug opened this issue Jul 17, 2013 · 3 comments
Assignees
Milestone

Comments

@scabug
Copy link

@scabug scabug commented Jul 17, 2013

I found very confusing behaviour for implicit import of scala.Predef.

http://stackoverflow.com/questions/17690183/explain-why-import-scala-predef-string-fails-build

Spec, section 9.1 Compilation units states the following:

Implicitly imported into every compilation unit are, in that order : the package java.lang, the package scala, and the object scala.Predef (§12.5).

But if I open the implementation:

https://github.com/scala/scala/blob/master/src/compiler/scala/tools/nsc/typechecker/Contexts.scala

method rootImports and scaladoc:

/** List of symbols to import from in a root context. Typically that

  • is java.lang, scala, and [[scala.Predef]], in that order. Exceptions:
    • if option -Yno-imports is given, nothing is imported
    • if the unit is java defined, only java.lang is imported
    • if option -Yno-predef is given, if the unit body has an import of Predef
  • among its leading imports, or if the tree is [[scala.Predef]], Predef is not imported.
    */
    protected def rootImports(unit: CompilationUnit): List[Symbol] = {
    assert(definitions.isDefinitionsInitialized, "definitions uninitialized")
if (settings.noimports) Nil
else if (unit.isJava) RootImports.javaList
else if (settings.nopredef || treeInfo.noPredefImportForUnit(unit.body)) {
  debuglog("Omitted import of Predef._ for " + unit)
  RootImports.javaAndScalaList
}
else RootImports.completeList

}

There is an exception in the comment: if the unit body has an import of Predef among its leading imports.

I think spec should mention this exception.

@scabug
Copy link
Author

@scabug scabug commented Jul 17, 2013

Imported From: https://issues.scala-lang.org/browse/SI-7672?orig=1
Reporter: Oleg Atamanenko (uthark)
Affected Versions: 2.10.2

@scabug
Copy link
Author

@scabug scabug commented Jul 17, 2013

Oleg Atamanenko (uthark) said:
Some specific observation:
If I add in the code import scala.Predef.String - I don't import Predef as a whole, just a scala.Predef.String, then scala.Predef is not implicitly added.

@scabug
Copy link
Author

@scabug scabug commented Mar 12, 2014

@adriaanm said:
Clarified in the upcoming markdown version of the spec.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants