Skip to content

Regression in exported extension method construction #15496

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

Closed
soronpo opened this issue Jun 22, 2022 · 4 comments
Closed

Regression in exported extension method construction #15496

soronpo opened this issue Jun 22, 2022 · 4 comments
Labels
area:export area:extension-methods itype:bug regression This worked in a previous version but doesn't anymore

Comments

@soronpo
Copy link
Contributor

soronpo commented Jun 22, 2022

Compiler version

v3.2.0-RC1 - error
v3.1.3-RC4 - OK

Minimized code

object Cont:
  extension [T <: Int & Singleton](x: T) inline def foo: Unit = {}
  extension (x: Int) inline def foo: Unit = {}

export Cont.*

object Test:
  var x = 1
  x.foo

Output

An extension method was tried, but could not be fully constructed:

    foo[T](x)    failed with

        Found:    (x : Int)
        Required: Int & Singleton

Expectation

No error.

@soronpo soronpo added itype:bug area:extension-methods regression This worked in a previous version but doesn't anymore area:export labels Jun 22, 2022
@griggt
Copy link
Contributor

griggt commented Jun 22, 2022

First bad commit is 806386e from #14967

@odersky
Copy link
Contributor

odersky commented Jun 22, 2022

Yes, that was a bug fix. The two extension methods have the same signature so only one of them can be exported. Workaround:

object Cont:
  extension [T <: Int & Singleton](x: T) 
    annotation.targetName("foo1") inline def foo: Unit = {}
  extension (x: Int) inline def foo: Unit = {}

export Cont.*

object Test:
  var x = 1
  x.foo

@odersky odersky closed this as completed Jun 22, 2022
@soronpo
Copy link
Contributor Author

soronpo commented Jun 22, 2022

@odersky shouldn't it have reported an overloading error (with targetName suggestion) instead of silently selecting one of the exported methods?

@odersky
Copy link
Contributor

odersky commented Jun 22, 2022

Normally it would have given an overloading error. But in this case it did not since the two methods are inline and therefore disappear at erasure, where the overloading check is made. I think it's a very special corner case, in fact.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:export area:extension-methods itype:bug regression This worked in a previous version but doesn't anymore
Projects
None yet
Development

No branches or pull requests

3 participants