Skip to content

Migrations from Dotty #302

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 3 commits into from
May 15, 2018
Merged

Migrations from Dotty #302

merged 3 commits into from
May 15, 2018

Conversation

allanrenucci
Copy link
Contributor

This changes were needed to make squants compile with Dotty (as part of our community build). I though I might as well upstream them

- Rewrite `apply = parse _` to `apply(x: Any) = parse(x)`:
  scala/scala3#2994
- Remove self type: scala/scala3#2214
@cquiroz
Copy link
Collaborator

cquiroz commented Apr 21, 2018

Thanks for your PR. It seems it covers various changes:

  • added tut plugin
  • update to sbt 1
  • changes to the code (I presume for dotty support)

Is this correct? Perhaps we should split it in several PRs?
is it possible to run the tests in dotty?

@allanrenucci
Copy link
Contributor Author

Hi @cquiroz,

This PR only covers two changes.

  • Update to sbt 1. The tut plugin is already used in the current build. It has to be enabled explicitly with sbt 1. Starting with the next release (0.8), Dotty will only be compatible with sbt 1.
  • Some source code migration to make squants compile with Dotty

I can split the changes into two PR if you want.

is it possible to run the tests in dotty?

Yes, it is possible to make squants cross compile with Dotty. This would require changes to the build and the CI script. Note that Dotty is currently not compatible with Scala.js and Scala Native.

@cquiroz
Copy link
Collaborator

cquiroz commented Apr 21, 2018

Thanks for clarifying the scope of the plugin, it would be nice to add it to the Travis build but I guess it could be done in another PR

@@ -13,7 +13,7 @@ package object strict {
object implicits {
implicit def mkSiUnitGroup[A <: Quantity[A]](implicit dimension: Dimension[A]): UnitGroup[A] = {
new UnitGroup[A] {
val units: Set[UnitOfMeasure[A]] = dimension.units.collect { case si: SiUnit => si }
val units: Set[UnitOfMeasure[A]] = dimension.units.filter(_.isInstanceOf[SiUnit])
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is this change required? I'd rather not have isInstanceOf in the code base

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This a bug in Dotty. See scala/scala3#3208. It is not clear if this will be fixed as one can always rewrite the code as:

dimension.units.collect { case si: UnitOfMeasure[A] with SiUnit => si }

However, I though using collect here was overkill since what it really doe is filter

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd rather have the collect call than isInstanceof

@@ -47,7 +47,7 @@ final class Dimensionless private (val value: Double, val unit: DimensionlessUni
*/
object Dimensionless extends Dimension[Dimensionless] {
def apply[A](n: A, unit: DimensionlessUnit)(implicit num: Numeric[A]) = new Dimensionless(num.toDouble(n), unit)
def apply = parse _
def apply(value: Any) = parse(value)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this change required by dotty?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. See this comment

Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

@cquiroz cquiroz mentioned this pull request Apr 25, 2018
@cquiroz
Copy link
Collaborator

cquiroz commented May 9, 2018

Are there any other opinions about this PR? Otherwise, I could merge it

Copy link
Collaborator

@cquiroz cquiroz left a comment

Choose a reason for hiding this comment

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

LGTM

@cquiroz cquiroz merged commit e50bc75 into typelevel:master May 15, 2018
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