Skip to content

Clarify migration path from Scala2 for "Structural Types" #4615

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
newca12 opened this issue Jun 2, 2018 · 4 comments
Closed

Clarify migration path from Scala2 for "Structural Types" #4615

newca12 opened this issue Jun 2, 2018 · 4 comments

Comments

@newca12
Copy link
Contributor

newca12 commented Jun 2, 2018

This is a followup of a discussion on gitter with @Blaisorblade and @smarter regarding the documentation of "Structural Types".
The two main issue with the documentation are :

  1. to be a bit misleading regarding the fact that current implementation still "reflection-based". dotty structural types allow for other implementations but right now we only have the reflection-based one
  2. not emphasize enough that in most cases importing scala.reflect.Selectable.reflectiveSelectable is sufficient for Scala2 code.

Regarding point 2 @smarter suggested to make the reflective stuff enabled by default with -language:Scala2 to allow cross-compilation.
That seemed to be fine but they are issues with Scala 2 code :

//import is not enought to make Scala2 code compile with dotty
import scala.reflect.Selectable.reflectiveSelectable
object Structural {
  class Example1 {
     def text(): String = "example"
  }
  val example1: Example1 = new Example1
  val example3: { def text(): String } = example1
  val res : String = example3.text
}

example3.text has not the same type with Scala 2 "String" and with dotty "() => String"
This is easy to fix manually using def text instead of def text()

I would have been happy to open a PR to improve the documentation but too many uncertainties still remain in order to do so.

@smarter
Copy link
Member

smarter commented Jun 2, 2018

example3.text has not the same type with Scala 2 "String" and with dotty "() => String"

It shouldn't compile at all with Dotty: http://dotty.epfl.ch/docs/reference/dropped/auto-apply.html

@newca12
Copy link
Contributor Author

newca12 commented Jun 5, 2018

OK so that mean that this minimized example code should not compile with dotty and deserve is own issue. Right ?

import scala.reflect.Selectable.reflectiveSelectable
class Test {
  def test(x: { def get(): Int }) = x.get
}

and that the example in this issue should compile with -language:Scala2,rewrite.
We can minimize it like in #4026

import scala.reflect.Selectable.reflectiveSelectable //should not be needed in Scala2 mode
class Test {
  def test(x: { def get(): Int }): Int = x.get
}

Is this also an other issue or just not implemented yet ?

Clarify migration path from Scala2 for "Structural Types" would be summed up then by : will the reflective stuff will be enabled by default in Scala 2 mode ?

@smarter
Copy link
Member

smarter commented Jun 5, 2018

It should be a separate issue yes.

@abgruszecki
Copy link
Contributor

Given the age of the issue, documentation changes and the presence of new migration guide, I think it's safe to close this issue. If there's a problem with the migration guide, please open a new issue.

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