Skip to content

Can't construct extension method via implicit conversion #18062

Closed
@rssh

Description

@rssh

Compiler version

3.3.2-RC1-bin-SNAPSHOT
(as for master branch from 2023-06-26)

Minimized code

package x

trait CB[X]

trait WrapperConvert[F[_],G[_]]{
  def apply[X](fx:F[X]):G[X]
}

object WrapperConvert {
  implicit def identityConvert[F[_]]:WrapperConvert[F,F] = ???
}

def cnAwait[X](cbx:CB[X]):X = ???

transparent inline given convertX[F[_],X](using WrapperConvert[F,CB]): Conversion[F[X],X] = {
  fx => cnAwait(summon[WrapperConvert[F,CB]](fx))
}

object X {

   def create: CB[Int] = ???

   def test(x:Int):Int = {
     create + x
   }

}

Output

[info] compiling 1 Scala source to /Users/rssh/tests/dotty/bad-infix-extensions/target/scala-3.3.2-RC1-bin-SNAPSHOT/classes ...
[error] -- [E008] Not Found Error: /Users/rssh/tests/dotty/bad-infix-extensions/src/main/scala/x/X.scala:24:12 
[error] 24 |     create + x
[error]    |     ^^^^^^^^
[error]    |     value + is not a member of x.CB[Int].
[error]    |     An extension method was tried, but could not be fully constructed:
[error]    |
[error]    |         {
[error]    |           val x$1$proxy1: x.WrapperConvert[x.CB, x.CB] =
[error]    |             x.WrapperConvert.identityConvert[x.CB]
[error]    |           {
[error]    |             {
[error]    |               def $anonfun(fx: x.CB[Any]): Any =
[error]    |                 {
[error]    |                   x.cnAwait[Any](x$1$proxy1.apply[Any](fx))
[error]    |                 }
[error]    |               closure($anonfun:Conversion[x.CB[Any], Any])
[error]    |             }
[error]    |           }
[error]    |         }.apply(create)
[warn] -- [E174] Syntax Warning: /Users/rssh/tests/dotty/bad-infix-extensions/src/main/scala/x/X.scala:15:92 
[warn] 15 |transparent inline given convertX[F[_],X](using WrapperConvert[F,CB]): Conversion[F[X],X] = {
[warn]    |                                                                                            ^
[warn]    |An inline given alias with a function value as right-hand side can significantly increase
[warn]    |generated code size. You should either drop the `inline` or rewrite the given with an
[warn]    |explicit `apply` method.
[warn] 16 |  fx => cnAwait(summon[WrapperConvert[F,CB]](fx))
[warn] 17 |}
[warn]    |
[warn]    | longer explanation available when compiling with `-explain`
[warn] one warning found
[error] one error found

Expectation

Should be compiled.

Note, that this is compiled with 3.3.0

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions