Skip to content

Lower bound widen to Any in type bound resolving #22012

Open
@tribbloid

Description

@tribbloid

Compiler version

3.5.2

Minimized code

trait TypeBound_Minimal {

  type Min
  type Max >: Min

  type Under = TypeBound_Minimal.K[? >: this.Min, ? <: this.Max] // <-- error happened here

  type Under_Dual1 = TypeBound_Minimal.Lt[Min, Max] // <- no error despite equivalent

  type Under_Dual2 = TypeBound_Minimal { // <- no error despite equivalent
    type Min >: TypeBound_Minimal.this.Min
    type Max <: TypeBound_Minimal.this.Max
  }

  trait TypeBound_Dual {
    type _Min = TypeBound_Minimal.this.Min
    type _Max = TypeBound_Minimal.this.Max

    type Under = TypeBound_Dual { // <- no error despite equivalent
      type _Min >: TypeBound_Dual.this._Min
      type _Max <: TypeBound_Dual.this._Max
    }
  }
}

object TypeBound_Minimal {

  type K[TMin, TMax >: TMin] = TypeBound_Minimal {
    type Min = TMin
    type Max = TMax
  }

  type Lt[TMin, TMax >: TMin] = TypeBound_Minimal {
    type Min >: TMin
    type Max <: TMax
  }
}

Output

[Error] /xxx/TypeBound_Minimal.scala:8:43: Type argument  <: TypeBound_Minimal.this.Max does not overlap with lower bound Any
two errors found

Expectation

Don't see a reason why the bounding argument TMin has to be widen to Any.

In general I found type argument unification has been superb for exact types (e.g. type T = F[Max]), but bounded free types (e.g. type T = F[_ >: Min <: Max]) was always treated as some kind of second-class citizen, while in practice type T = F[Max] is merely an alias of type T = F[_ >: Max <: Max], can we have a compiler spec to elevate them to first-class citizens?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions