scala / scala3

The Scala 3 compiler, also known as Dotty.
https://dotty.epfl.ch
Apache License 2.0
5.88k stars 1.06k forks source link

Extension method with dependent type bounds #19197

Open nicolasstucki opened 11 months ago

nicolasstucki commented 11 months ago

Compiler version

3.3.1

Minimized code

extension (tuple: Tuple)
  def *:[T >: tuple.type <: Tuple, H](x: H): H *: T = ???

Output

2 |  def `*:`[T >: tuple.type <: Tuple, H](x: H): H *: T = ???
  |                ^^^^^
  |                Not found: tuple - did you mean Tuple?

The issue seems to come from how we handle type parameters

[[syntax trees at end of                     typer]]
    extension [T >: tuple.type <: Tuple, H >: Nothing <: Any](tuple: Tuple)
      def *:(x: H): *:[H, T] = ???

It should be the same as in

extension (tuple: Tuple)
  def ok[T >: tuple.type <: Tuple, H](x: H): H *: T = ???
[[syntax trees at end of                     typer]]
    extension (tuple: Tuple) def ok[T >: tuple.type <: Tuple,
      H >: Nothing <: Any](x: H): *:[H, T] = ???

Expectation

Should compile

bishabosha commented 11 months ago

you would have to lift out type parameters when you do the swap

nicolasstucki commented 11 months ago

The swap seems to be fundamentally broken. The scoping while swapping adds too many restrictions.

nicolasstucki commented 11 months ago

It seems that this and other use cases start working if we do not swap the parameters. They are sapped correctly at the call site. I will investigate further.