Skip to content

update export.md: clarify how extensions are exported #13327

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

Merged
merged 1 commit into from
Aug 20, 2021

Conversation

unkarjedy
Copy link
Contributor

Docs mention how types, terms, and givens are exported, but mention nothing about extensions.

object Members {
  extension (s: String) {
    def ext1: String = ???
    def ext2(p: Int) = ???
  }
}

object Usage {
  export Members.*
}

produces

scalac: package <empty> {
  final lazy module val Members: Members = new Members()
  final module class Members() extends Object() { this: Members.type =>
    extension (s: String) def ext1: String = ???
    extension (s: String) def ext2(p: Int): Nothing = ???
  }
  final lazy module val Usage: Usage = new Usage()
  final module class Usage() extends Object() { this: Usage.type =>
    export Members.*
    extension (s: String) final def ext1: String = Members.ext1(s)
    extension (s: String) final def ext2(p: Int): Nothing = Members.ext2(s)(p)
  }
}

```scala
object Members {
  given x: Int = 4
  given y: Comparable[String] with  {override def compareTo(o: String): Int = ???}

  extension (s: String) {
    def ext1: String = ???
    def ext2(p: Int) = ???
  }
}


object Usage {
  export Members.*
}
```
produces
```scala
scalac: package <empty> {
  final lazy module val Members: Members = new Members()
  final module class Members() extends Object() { this: Members.type =>
    final lazy given val x: Int = 4
    final lazy module given val y: Members.y = new Members.y()
    final module class y() extends Object(), Comparable[String] { 
      this: Members.y.type =>
      override def compareTo(o: String): Int = ???
    }
    extension (s: String) def ext1: String = ???
    extension (s: String) def ext2(p: Int): Nothing = ???
  }
  final lazy module val Usage: Usage = new Usage()
  final module class Usage() extends Object() { this: Usage.type =>
    export Members.*
    extension (s: String) final def ext1: String = Members.ext1(s)
    extension (s: String) final def ext2(p: Int): Nothing = Members.ext2(s)(p)
  }
}
```
Copy link
Member

@bishabosha bishabosha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@bishabosha bishabosha merged commit 639288d into scala:master Aug 20, 2021
@bishabosha
Copy link
Member

@unkarjedy we actually shouldnt be updating the docs at this repo anymore, please can you replicate the same changes for this PR and #13339 at https://github.com/scala/docs.scala-lang

@unkarjedy
Copy link
Contributor Author

OK

But to avoid duplication and confusion in the future I think "Edit on Github" link should be removed from all the old pages

@unkarjedy
Copy link
Contributor Author

BTW, I understand that it's subjective, but https://dotty.epfl.ch/docs/ design looks prettier and more modern

@unkarjedy
Copy link
Contributor Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants