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

Can't construct extension method via implicit conversion #18062

Closed
rssh opened this issue Jun 26, 2023 · 1 comment · Fixed by #18085
Closed

Can't construct extension method via implicit conversion #18062

rssh opened this issue Jun 26, 2023 · 1 comment · Fixed by #18085
Assignees
Labels
area:typer itype:bug regression This worked in a previous version but doesn't anymore
Milestone

Comments

@rssh
Copy link
Contributor

rssh commented Jun 26, 2023

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

@rssh rssh added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Jun 26, 2023
@Kordyjan Kordyjan added regression This worked in a previous version but doesn't anymore area:typer and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Jun 27, 2023
@Kordyjan
Copy link
Contributor

@rssh: Thanks for the report and the minimization.

@dwijnand: can it be caused by 701254f ?

@Kordyjan Kordyjan added this to the 3.3.2 milestone Jun 27, 2023
@dwijnand dwijnand changed the title compiler can't construct extension method via implicit conversion (regression). Can't construct extension method via implicit conversion Jun 27, 2023
@dwijnand dwijnand linked a pull request Jun 28, 2023 that will close this issue
odersky added a commit that referenced this issue Jun 28, 2023
@Kordyjan Kordyjan modified the milestones: 3.3.2, 3.4.0 Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:typer itype:bug regression This worked in a previous version but doesn't anymore
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants