2013-07-17 2 views
2

스칼라 가져 오기와 관련하여 매우 이상한 문제가 발견되었습니다. 오류없이왜 scala.Predef.String 가져 오기 빌드가 실패하는지 설명하십시오.

package test_scala_predef 

object App extends App { 

    classOf[T] 
    println("Hello World!") 
} 

class T { 

} 

이 클래스는 컴파일 :

나는 샘플 클래스를 썼다.

[INFO] Compiling 1 source files to /home/uthark/src/_/test_scala_predef/target/classes at 1374028063588 
[ERROR] /home/uthark/src/_/test_scala_predef/src/main/scala/test_scala_predef/App.scala:10: error: not found: value classOf 
[INFO] classOf[T] 
[INFO] ^
[ERROR] /home/uthark/src/_/test_scala_predef/src/main/scala/test_scala_predef/App.scala:11: error: not found: value println 
[INFO] println("Hello World!") 
[INFO] ^
[ERROR] two errors found 

내가 scala.Predef에서 특정 가져 오기를 추가 한 후, scala.Predef._의 다음 implict 가져 오기가 아니라고, 생각이 : 내가 추가하는 경우

그러나,

import scala.Predef.String 

는 내가 컴파일 오류를 얻을 수 덧붙였다. 하지만 스칼라 문서에서 그걸 발견 할 수는 없습니다. 누구든지 문서의 관련 섹션을 가리킬 수 있습니까?

Scala Language Specification (PDF), 12.5 절, scala.Predef을 조사했는데 관련이 없었습니다.

나는

답변

2

나는 소스에서 답을 발견 (순간 2.10.2) 가능한 최신 안정 스칼라 버전을 사용하십시오.

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

는 :

/** 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 
    } 

이 내 질문에 대답을 제공합니다. 단위 몸이

또한 자사의 주요 수입 중 PREDEF의 수입이있는 경우 그것이 #scala IRC에서 채팅, ... :

예외 :

핵심 문장이있다 스칼라 문제 추적 시스템에서 버그를 만들 것을 제안 했으므로 그렇게했습니다. https://issues.scala-lang.org/browse/SI-7672

+0

좋습니다. –