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

Exporting extension methods with a fixed receiver #22388

Open
prolativ opened this issue Jan 16, 2025 · 1 comment
Open

Exporting extension methods with a fixed receiver #22388

prolativ opened this issue Jan 16, 2025 · 1 comment

Comments

@prolativ
Copy link
Contributor

Compiler version

3.3.4, 3.7.0-RC1-bin-20250116-0f9e502-NIGHTLY

Minimized code

class Foo():
  def x1: Int = 123

object Foo:
  extension (foo: Foo)
    def x2: Int = 123

  implicit class FooOps(foo: Foo):
    def x3: Int = 123

class Bar():
  val foo = Foo()
  export foo.x1
  export foo.x2

object Bar:
  extension (bar: Bar)
    private def fooOps = Foo.FooOps(Foo())
    export fooOps.x3


val xs = Seq(
  Foo().x1,
  Foo().x2,
  Foo().x3,
  Bar().x1,
  Bar().x2,
  Bar().x3
)

Output

[error] /tmp/ExportExtension.scala:14:14
[error] no eligible member x2 at this.foo
[error]   export foo.x2
[error]              ^^
[error] /tmp/ExportExtension.scala:27:3
[error] value x2 is not a member of Bar - did you mean Bar.x1?
[error]   Bar().x2,
[error]   ^^^^^^^^

Expectation

It should be possible to export an extension method applied on a specific receiver.

Though technically this might be considered a lack of a feature rather than a bug, this is a point were extension methods are less useful than implicit classes.

Considerations

Could this work with export foo.* or would extension exports be restricted to explicitly named methods?

@prolativ prolativ added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Jan 16, 2025
@soronpo
Copy link
Contributor

soronpo commented Jan 16, 2025

This is not a bug. Lack of feature and currently extension is not considered as a new block scope, so it does not support import nor export.

@Gedochao Gedochao added itype:enhancement area:extension-methods area:export and removed itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Jan 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants