Skip to content

extension methods should not pollute global scope #17659

Closed
@scf37

Description

@scf37

Right now extension methods are translated to ordinary functions and can be called as such:

extension (s: String) {
  def sayHello: String = s"Hello, $s"
}
"world".sayHello // Hello, world
sayHello("world") // Hello, world

Which limits its usage in libraries - for example, re-implementing scala.collectionStringOps as extension functions will add tenths of useless functions to visible scope causing confusion and potential problems with overload resolution and compatibility.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions