Skip to content
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

Lower bound widen to Any in type bound resolving #22012

Open
tribbloid opened this issue Nov 22, 2024 · 2 comments
Open

Lower bound widen to Any in type bound resolving #22012

tribbloid opened this issue Nov 22, 2024 · 2 comments

Comments

@tribbloid
Copy link

tribbloid commented Nov 22, 2024

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?

@tribbloid tribbloid added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Nov 22, 2024
@Gedochao Gedochao added itype:enhancement area:spec area:f-bounds and removed itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Nov 25, 2024
@tribbloid
Copy link
Author

@Gedochao this is not a bug but an enhancement in fixed-point-bounds? How could you be sure?

@Gedochao
Copy link
Contributor

@tribbloid my bad, I assigned the wrong label.

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

2 participants