Skip to content

type signature of subclass member resolves to the wrong path-dependent type if inheriting multiple inner traits with identical path #16724

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

Open
tribbloid opened this issue Jan 18, 2023 · 2 comments
Labels
area:refchecks area:reporting Error reporting including formatting, implicit suggestions, etc itype:bug

Comments

@tribbloid
Copy link

Compiler version

3.2.1

Minimized code

  object AsDependentType {

    trait Gen {

      type Upper

      trait CoVP {
        type T <: Upper
        val vv: Upper
      }
    }

    object GenY extends Gen {

      type Upper = Product
      trait P1 extends CoVP {

        val vv: Product
      }
    }

    object GenZ extends Gen {

      type Upper = Tuple1[Int]
      trait P2 extends GenY.P1 with CoVP {

        val vv: Tuple1[Int]
      }
    }
  }

Output

[Error] /home/peng/git/dottyspike/src/main/scala/com/tribbloids/spike/dotty/Covariance.scala:46:13: error overriding value vv in trait CoVP of type Gen.this.Upper;
  value vv of type Tuple1[Int] has incompatible type
one error found

Expectation

It should compile successfully. The error information is clearly wrong, All 3 instances of Gen.this.Upper (Upper, Product, Tuple1[Int]) are super types of Tuple1[Int]

@tribbloid tribbloid added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Jan 18, 2023
@tribbloid tribbloid changed the title type signature of subclass resolves to the wrong path-dependent type if inherits multiple inner traits type signature of subclass resolves to the wrong path-dependent type if inheriting multiple inner traits Jan 19, 2023
@tribbloid tribbloid changed the title type signature of subclass resolves to the wrong path-dependent type if inheriting multiple inner traits type signature of subclass member resolves to the wrong path-dependent type if inheriting multiple inner traits Jan 19, 2023
@tribbloid tribbloid changed the title type signature of subclass member resolves to the wrong path-dependent type if inheriting multiple inner traits type signature of subclass member resolves to the wrong path-dependent type if inheriting multiple inner traits with identical paths Jan 19, 2023
@tribbloid tribbloid changed the title type signature of subclass member resolves to the wrong path-dependent type if inheriting multiple inner traits with identical paths type signature of subclass member resolves to the wrong path-dependent type if inheriting multiple inner traits with identical path Jan 19, 2023
@odersky
Copy link
Contributor

odersky commented Jan 20, 2023

Scala 2.13 reports:

 trait P2 inherits different type instances of trait CoVP:
AsDependentType.GenZ.CoVP and AsDependentType.GenY.CoVP
    trait P2 extends GenY.P1 with CoVP {

I believe that's the root error, which should be reported in Scala 3 as well.

@odersky odersky added area:reporting Error reporting including formatting, implicit suggestions, etc area:refchecks and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Jan 20, 2023
@tribbloid
Copy link
Author

tribbloid commented Jan 20, 2023

No sure professor. Are GenY.CovP and GenZ.CovP supposed to be different types in DOT logic, regardless of whether GenY, GenZ are packages or objects?

These works in dotty 3.2 though:

  object AsDependentType {

    trait Gen {

      type Upper

      trait CoVP {
        type T <: Upper
      }
    }

    object GenY extends Gen {

      type Upper = Product
      trait P1 extends CoVP {}
    }

    object GenZ extends Gen {

      type Upper = Tuple1[Int]
      trait P2 extends CoVP with GenY.P1 {}
    }
  }
  object AsDependentType {

    trait Gen {

      type Upper

      trait CoVP {
        type T <: Upper
        val vv: Upper
      }
    }

    object GenY extends Gen {

      type Upper = Product
      trait P1 extends CoVP {

        val vv: Product
      }
    }

    object GenZ extends Gen {

      type Upper = Tuple1[Int]
      trait P2 extends CoVP {
        self: GenY.P1 =>
        val vv: Tuple1[Int]
      }
    }
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:refchecks area:reporting Error reporting including formatting, implicit suggestions, etc itype:bug
Projects
None yet
Development

No branches or pull requests

2 participants