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

search for implicit conversions should continue after single abstract method conversion failed #22363

Open
tribbloid opened this issue Jan 13, 2025 · 0 comments
Labels
area:implicits related to implicits itype:bug

Comments

@tribbloid
Copy link

Compiler version

3.6.2

Minimized code

The following code attempts to unify DepFn (in shapeless 2) with Function1 (in standard library)

the bound type Out cannot be used directly in covariant position unless fully defined (with upper & lower bound), this is a much harder problem which IS NOT in the scope of this ticket. However, this is avoided in the implicit given fn2DepFn[I, O], which fully defined type Out.

object FnAsDepFn {

  trait DepFnK[-I] extends Function1[I, ?] {

    type Out

    def apply(v: I): Out
  }

  trait DepFn[-I, +O] extends Function1[I, O] with DepFnK[I] {
    type Out <: O
  }

  given fn2DepFn[I, O]: Conversion[(I => O), DepFn[I, O]] = {
    new Conversion[(I => O), DepFn[I, O]] {

      def apply(v1: I => O): DepFn[I, O] = {
        new DepFn[I, O] {
          type Out = O
          def apply(v: I): O = v1(v)
        }
      }
    }
  }

  val fnGround: DepFn[Int, String] = fn2DepFn { v =>
    "" + v
  }

  val fn1: DepFn[Int, String] = { v =>
    "" + v
  }

  val fn2: DepFn[Int, String] = { (v: Int) =>
    " " + v
  }

  val fn3: DepFn[?, ?] = { (v: Int) =>
    " " + v
  }
}

Output

/home/peng/git/dottyspike/core/src/main/scala/com/tribbloids/spike/dotty/FnAsDepFn.scala:33:5
Found:    String
Required: com.tribbloids.spike.dotty.FnAsDepFn.DepFn[Int, String]#Out

Explanation
===========

Tree: "".+(v)
I tried to show that
  String
conforms to
  com.tribbloids.spike.dotty.FnAsDepFn.DepFn[Int, String]#Out
but none of the attempts shown below succeeded:

  ==> String  <:  com.tribbloids.spike.dotty.FnAsDepFn.DepFn[Int, String]#Out CachedTypeRef CachedTypeRef  = false

The tests were made under the empty constraint

    "" + v

/home/peng/git/dottyspike/core/src/main/scala/com/tribbloids/spike/dotty/FnAsDepFn.scala:37:5
Found:    String
Required: com.tribbloids.spike.dotty.FnAsDepFn.DepFn[Int, String]#Out

Explanation
===========

Tree: " ".+(v)
I tried to show that
  String
conforms to
  com.tribbloids.spike.dotty.FnAsDepFn.DepFn[Int, String]#Out
but none of the attempts shown below succeeded:

  ==> String  <:  com.tribbloids.spike.dotty.FnAsDepFn.DepFn[Int, String]#Out CachedTypeRef CachedTypeRef  = false

The tests were made under the empty constraint

    " " + v

/home/peng/git/dottyspike/core/src/main/scala/com/tribbloids/spike/dotty/FnAsDepFn.scala:41:5
Found:    String
Required: com.tribbloids.spike.dotty.FnAsDepFn.DepFn[Any, Any]#Out

Explanation
===========

Tree: " ".+(v)
I tried to show that
  String
conforms to
  com.tribbloids.spike.dotty.FnAsDepFn.DepFn[Any, Any]#Out
but none of the attempts shown below succeeded:

  ==> String  <:  com.tribbloids.spike.dotty.FnAsDepFn.DepFn[Any, Any]#Out CachedTypeRef CachedTypeRef  = false

The tests were made under the empty constraint

    " " + v

Expectation

The underdefined type Out problem should be circumvented if the given can be used, instead, it was ignored after SAM rewriting is attempted with an underdefined type Out

@tribbloid tribbloid added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Jan 13, 2025
@Gedochao Gedochao added area:implicits related to implicits and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Jan 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:implicits related to implicits itype:bug
Projects
None yet
Development

No branches or pull requests

2 participants