Skip to content

test_sbt broken in CI: Synthetic apply in private companion object #10728

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

Closed
adpi2 opened this issue Dec 9, 2020 · 8 comments
Closed

test_sbt broken in CI: Synthetic apply in private companion object #10728

adpi2 opened this issue Dec 9, 2020 · 8 comments
Assignees

Comments

@adpi2
Copy link
Member

adpi2 commented Dec 9, 2020

Minimized code

// A.scala
case class A(x: Int)
private object A
// B.scala
object B {
  val f: Int => A = A
  f(0)
}

Output

Compile successfully with a warning

> scalac A.scala B.scala
[info] running (fork) dotty.tools.dotc.Main -classpath /home/piquerez/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.4/scala-library-2.13.4.jar:/home/piquerez/lampepfl/dotty/library/../out/bootstrap/scala3-library-bootstrapped/scala-3.0.0-M3/scala3-library_3.0.0-M3-3.0.0-M3-bin-SNAPSHOT.jar B.scala A.scal
-- Warning: B.scala:2:20 -------------------------------------------------------
2 |  val f: Int => A = A
  |                    ^
  |The method `apply` is inserted. The auto insertion will be deprecated, please write `A.apply` explicitly.
1 warning found
[success] Total time: 63 s (01:03), completed Dec 9, 2020, 10:35:11 PM

Expectation

It should not compile because the apply method of the private companion object should not exist

@adpi2 adpi2 added the itype:bug label Dec 9, 2020
@smarter
Copy link
Member

smarter commented Dec 9, 2020

Private on a top-level definition means package-private in both Scala 2 and 3, so I don't think there is a bug here.

@smarter smarter closed this as completed Dec 9, 2020
@adpi2
Copy link
Member Author

adpi2 commented Dec 9, 2020

Then I don't understand how this test is supposed to work: https://github.com/lampepfl/dotty/tree/master/sbt-dotty/sbt-test/source-dependencies/synthetic-companion

@adpi2
Copy link
Member Author

adpi2 commented Dec 9, 2020

I guess there is an issue that is badly formulated in my previous description

@adpi2 adpi2 reopened this Dec 9, 2020
@adpi2 adpi2 changed the title Private companion object is accessible Synthetic apply in private companion object Dec 9, 2020
adpi2 added a commit to adpi2/scala3 that referenced this issue Dec 9, 2020
@smarter
Copy link
Member

smarter commented Dec 9, 2020

I assume this was broken by #7207 /cc @liufengyun

@liufengyun
Copy link
Contributor

It should not compile because the apply method of the private companion object should not exist

The method apply does exist, it's synthesized. I checked Scala 2.13, the synthesized apply exists as well. But I don't know why it reports an error.

@smarter
Copy link
Member

smarter commented Dec 9, 2020

Weird indeed. Anyway we can fix the test to actually directly check the subtyping relationship so it won't be influenced by whether or not A is expanded to A.apply:

object B {
  summon[A.type <:< (Int => A)]
}

@smarter smarter changed the title Synthetic apply in private companion object test_sbt broken in CI: Synthetic apply in private companion object Dec 9, 2020
@liufengyun
Copy link
Contributor

It seems it's Scala 2 behavior is inconsistent, the following code type checks in Scala 2:

// A.scala
case class A(x: Int)
private object A

// B.scala
object B {
  val f: Int => A = x => A(x)          // instead of `A`
  f(0)
}

The only difference is eta-expansion of A to x => A(x).

adpi2 added a commit to adpi2/scala3 that referenced this issue Dec 11, 2020
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

3 participants