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

protected class definition is visible in inner scopes via import statement #12589

Open
unkarjedy opened this issue May 11, 2022 · 4 comments
Open

Comments

@unkarjedy
Copy link

related https://youtrack.jetbrains.com/issue/SCL-20190
might be related: #11554

Reproduction steps

ThisBuild / version := "0.1.0-SNAPSHOT"

ThisBuild / scalaVersion := "2.12.15"

lazy val root = (project in file("."))
  .settings(
    name := "untitled9",
    libraryDependencies ++= Seq(
      "org.apache.spark" %% "spark-sql" % "3.2.1",
    )
  )

org.apache.spark.sql.types.AtomicType is protected[sql]
Note, it's companion object is public.

These examples are expectedly not compiled, producing compilation error:

object Main {
  val a: org.apache.spark.sql.types.AtomicType = ???
}
import org.apache.spark.sql.types.AtomicType

object Main {
  val a: AtomicType = ???
}

These are unexpectedly compiled fine without any compilation errors:

import org.apache.spark.sql.types.AtomicType

object Main {
  {
    val a: AtomicType = ???
  }
}
import org.apache.spark.sql.types.AtomicType

object Main {
  def foo = {
    val a: AtomicType = ???
  }
}
@SethTisue
Copy link
Member

Curious if the bug also exists in Scala 3.

@dwijnand dwijnand added this to the Backlog milestone Jun 30, 2022
@som-snytt
Copy link

Gee, I get the opposite symptom, where it errors on the locals but not the member (both 2.12 and 2.13):

scalac -d out -cp out client.scala
client.scala:9: error: not found: type Thing
      def inU: Thing = ???
               ^
client.scala:14: error: not found: type Thing
      def inF: Thing = ???
               ^
client.scala:19: error: not found: type Thing
      def inBraces: Thing = ???
                    ^
three errors found

where as in spark there is a public companion (doesn't seem to matter)

package p.q.r.s {
  protected[r] class Thing
  object Thing
}

and

package p {
  import p.q.r.s._

  object Test {
    def t: Thing = ???

    def u: Any = locally {
      def inU: Thing = ???
      null
    }

    def f = {
      def inF: Thing = ???
      null
    }

    {
      def inBraces: Thing = ???
      ()
    }
  }

  package q.r {
    object OK {
      def t: Thing = ???
    }
  }
}

@som-snytt
Copy link

Scalac 3 correctly issues 4 errors:

scalac -d out -cp out client.scala
-- [E006] Not Found Error: client.scala:6:11 ---------------------------------------------------------------------------
6 |    def t: Thing = ???
  |           ^^^^^
  |           Not found: type Thing

longer explanation available when compiling with `-explain`
-- [E006] Not Found Error: client.scala:9:15 ---------------------------------------------------------------------------
9 |      def inU: Thing = ???
  |               ^^^^^
  |               Not found: type Thing

longer explanation available when compiling with `-explain`
-- [E006] Not Found Error: client.scala:14:15 --------------------------------------------------------------------------
14 |      def inF: Thing = ???
   |               ^^^^^
   |               Not found: type Thing

longer explanation available when compiling with `-explain`
-- [E006] Not Found Error: client.scala:19:20 --------------------------------------------------------------------------
19 |      def inBraces: Thing = ???
   |                    ^^^^^
   |                    Not found: type Thing

longer explanation available when compiling with `-explain`
4 errors found

@som-snytt
Copy link

som-snytt commented Jun 30, 2022

OK, I confirmed the first example. It errors with val but not with def. Ha! Just when I thought I understood how anything works. (Or doesn't work.)

However, I could not reproduce the "compiles fine":

➜  example sbt "; clean; compile"
[info] welcome to sbt 1.6.2 (Oracle Corporation Java 18.0.1.1)
[info] loading global plugins from .../.sbt/1.0/plugins
[info] loading project definition from .../t12589/example/project
[info] loading settings for project root from build.sbt ...
[info] set current project to untitled9 (in build file:.../t12589/example/)
[success] Total time: 0 s, completed Jun 30, 2022, 9:42:08 AM
[info] compiling 1 Scala source to .../t12589/example/target/scala-2.12/classes ...
[error] .../t12589/example/src/main/scala/example.scala:9:14: not found: type AtomicType
[error]     def inF: AtomicType = ???     // error!
[error]              ^
[error] .../t12589/example/src/main/scala/example.scala:13:14: not found: type AtomicType
[error]     val inG: AtomicType = ???     // error!
[error]              ^
[error] .../t12589/example/src/main/scala/example.scala:19:12: not found: type AtomicType
[error]     val a: AtomicType = ???
[error]            ^
[error] three errors found
[error] (Compile / compileIncremental) Compilation failed
[error] Total time: 4 s, completed Jun 30, 2022, 9:42:12 AM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants