Skip to content

trait inherits conflicting members if they have common type context bound used in inline functions if they are defined in different files #10477

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
rssh opened this issue Nov 24, 2020 · 1 comment · Fixed by #11534
Assignees
Milestone

Comments

@rssh
Copy link
Contributor

rssh commented Nov 24, 2020

Minimized code

File 1:

package gopher

import scala.util.Try

def await[F[_],T](f:F[T])(using am:CpsAsyncMonad[F]):T = ???

trait CpsAsyncMonad[F[_]]:

   def adoptCallbackStyle[A](source: (Try[A]=>Unit) => Unit): F[A]

trait IChannel[F[_]:CpsAsyncMonad, A]:

   def aread:F[A] =
      summon[CpsAsyncMonad[F]].adoptCallbackStyle(f => addReader(f))

   inline def read: A = await(aread)

   def addReader(f: Try[A]=>Unit): Unit


trait IOChannel[F[_]:CpsAsyncMonad,I,O] extends IChannel[F,I] with OChannel[F,O]

File 2:

package gopher

import scala.util.Try

trait OChannel[F[_]:CpsAsyncMonad, A]:

   def awrite(a:A):F[Unit] =
     summon[CpsAsyncMonad[F]].adoptCallbackStyle(f =>
         addWriter(a, f)
     )

   inline def write(a:A): Unit = await(awrite(a))

   def addWriter(a:A, f: Try[Unit]=>Unit): Unit

Output

[info] compiling 2 Scala sources to /Users/rssh/work/oss/dotty-bug1/jvm/target/scala-3.0.0-M2/classes ...
[error] -- Error: /Users/rssh/work/oss/dotty-bug1/shared/src/main/scala/gopher/Channel.scala:21:6 
[error] 21 |trait IOChannel[F[_]:CpsAsyncMonad,I,O] extends IChannel[F,I] with OChannel[F,O]
[error]    |      ^
[error]    |trait IOChannel inherits conflicting members:
[error]    |  method inline$evidence$1 in trait IChannel of type => gopher.CpsAsyncMonad[F]  and
[error]    |  method inline$evidence$1 in trait OChannel of type => gopher.CpsAsyncMonad[F]
[error]    |(Note: this can be resolved by declaring an override in trait IOChannel.)
[error] one error found
[error] (gopherJVM / Compile / compileIncremental) Compilation failed

Expectation

should compile.

Note, that if I put all definitions in one file -- compilation is successful.

@odersky
Copy link
Contributor

odersky commented Feb 25, 2021

Minimization:

trait A:
  private def f: Int = 1
  inline def g = f
trait B:
  private def f: Int = 1
  inline def h = f
class C extends A, B

gives:

-- Error: i10477.scala:7:6 -----------------------------------------------------
7 |class C extends A, B
  |      ^
  |      class C inherits conflicting members:
  |        method inline$f in trait A of type => Int  and
  |        method inline$f in trait B of type => Int
  |      (Note: this can be resolved by declaring an override in class C.)
1 error found

The problem is that the names of inline accessors are generated from the name of the private definition they access.

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

Successfully merging a pull request may close this issue.

4 participants