scala / bug

Scala 2 bug reports only. Please, no questions — proper bug reports only.
https://scala-lang.org
230 stars 21 forks source link

Member type bounds in a compound type shadow the original bounds of the declaring type #12164

Open noresttherein opened 3 years ago

noresttherein commented 3 years ago

Probably 'not a bug' but a long known undocumented feature too hard to fix, but I reduced and isolated it, so here it goes:

reproduction steps

using Scala 2.13.3,

    trait Thing { thisThing =>
        type Generalized >: Self <: Thing {
            type Generalized <: thisThing.Generalized
        }
        type Self <: Thing {
            type Generalized = thisThing.Generalized
            type Self = thisThing.Self
        }

        implicitly[Adapter[Generalized] <:< Universal[Generalized]] //does not compile
    }

    trait Wrapper extends Thing {
        type GeneralizedAdapted >: Adapted <: Thing
        type Adapted <: Thing
    }

    trait Adapter[+T <: Thing] extends Wrapper {
        val thing :T
        type Generalized = Adapter[thing.Generalized]
        type Self = Adapter[thing.Self]
        type GeneralizedAdapted = thing.Generalized
        type Adapted = thing.Self
        implicitly[Adapted <:< GeneralizedAdapted]
    }

    type Universal[+T <: Thing] = Wrapper { type Adapted <: T }

problem

C:\slang\src\test\scala\Playground.scala:20:5
Cannot prove that Playground.Adapter[Thing.this.Generalized] <:< Playground.Universal[Thing.this.Generalized].
        implicitly[Adapter[Generalized] <:< Universal[Generalized]] 

I would expect it to compile:

Adapter[_1.Generalized] <:< Universal[_1.Generalized]  forSome { val _1 :Thing } ?
Adapter[_1.Generalized] <:< Wrapper { type Adapted <: _1.Generalized } ?
_2.Adapted <:< _1.Generalized forSome { val _2 :Adapter[_1.Generalized] } ?
    _3.Self <:<  _1.Generalized forSome { val _3 : _1.Generalized } ?
        _3.Generalized <:< _1.Generalized ? (because _3.Self <:< _3.Generalized)
        true
    _2.GeneralizedAdapted <:< 1.Generalized ? (because _2.Adapted <:< _2.GeneralizedAdapted)
   _3.Generalized <:< _1.Generalized forSome { val _3 : _1.Generalized } ?
   true

But I do not know the principles of the working of the typer or the exact compound type semantics.

By the way: is there, honestly, any point in reporting bugs for features of Scala 2 being dropped, now that Scala 3 is round the corner?

SethTisue commented 3 years ago

By the way: is there, honestly, any point in reporting bugs for features of Scala 2 being dropped, now that Scala 3 is round the corner?

Even bug reports that are unlikely to be fixed are still valuable as documentation. Someone might hit the same thing in the future, find the ticket, and find it helpful, perhaps add a comment with a workaround or some further insight, etc. (And every so often, such a bug does get fixed after all!)

Although such bug reports might not always attract any comments, we genuinely appreciate them nonetheless.

noresttherein commented 3 years ago

Thanks for weighting in. I am aware about the Self = thisThing.Self, but it doesn't hold in the real problem, going against the whole principle of Self being the concrete type and Generalized being its some super type serving as a class of abstraction for several subtypes.