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

prepare for Dotty #406

Merged
merged 1 commit into from
Jul 29, 2020
Merged

prepare for Dotty #406

merged 1 commit into from
Jul 29, 2020

Conversation

larsrh
Copy link
Contributor

@larsrh larsrh commented Jul 29, 2020

I've verified that squantsJVM builds with Dotty 0.26.0-RC1 (tests still pending).

@@ -123,7 +123,7 @@ abstract class Quantity[A <: Quantity[A]] extends Serializable with Ordered[A] {
* @return Quantity
*/
def negate: A = unit(-value)
def unary_-(): A = negate
def unary_- : A = negate
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 looks like it should be a binary-compatible change. If unary_- had an empty parameter lists, Dotty would prevent you from calling it as -x.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I was planning to put this as a separate PR to be included in the current master. This triggers warnings on 2.13.3

@@ -171,7 +171,7 @@ abstract class Quantity[A <: Quantity[A]] extends Serializable with Ordered[A] {
* @return
*/
override def equals(that: Any) = that match {
case x: Quantity[A] if x.dimension == dimension ⇒ value == x.to(unit)
case x: Quantity[_] if x.dimension == dimension ⇒ value == x.asInstanceOf[Quantity[A]].to(unit)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Dotty prohibits this type assertion (Scala 2 should warn about this). I'm not entirely sure if my "fix" is correct.

@@ -144,7 +144,7 @@ case class DoubleVector(coordinates: Double*) extends SVector[Double] {

type SVectorType = DoubleVector

def magnitude: Double = math.sqrt(coordinates.toTraversable.map(v ⇒ v * v).sum)
def magnitude: Double = math.sqrt(coordinates.map(v ⇒ v * v).sum)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Most of the collection conversions here seemed redundant to me, so I deleted them.

@@ -3,7 +3,7 @@ package squants.motion
import squants.mass.MomentOfInertia
import squants.space._
import squants.time.{Seconds, Time, TimeDerivative}
import squants.{AbstractQuantityNumeric, Dimension, Length, PrimaryUnit, Quantity, SiUnit, UnitConverter, UnitOfMeasure}
import squants.{AbstractQuantityNumeric, Dimension, Length, PrimaryUnit, Quantity, SiUnit, SquantifiedDouble, UnitConverter, UnitOfMeasure}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

SquantifiedDouble is an implicit class that triggers somewhere in this file and I'm surprised that it compiled under Scala 2 (it needs to be in scope).

@larsrh
Copy link
Contributor Author

larsrh commented Jul 29, 2020

Tests prove to be difficult. I have another branch where I'm down to 126 errors, but I'm keeping it on hold because it's with an old version of Dotty (0.24). I'd rather wait for ScalaTest to come out for 0.26.

@cquiroz
Copy link
Collaborator

cquiroz commented Jul 29, 2020

How did you verify this compiles in dotty?

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.

Thanks looks great

@larsrh
Copy link
Contributor Author

larsrh commented Jul 29, 2020

How did you verify this compiles in dotty?

I have patched the build definition to include the sbt-dotty plugin and fiddled around with some dependencies, then basically:

$ sbt
> ++0.26.0-RC1!
> squantsJVM/compile

@cquiroz cquiroz merged commit c3aa6bc into master Jul 29, 2020
@cquiroz cquiroz deleted the topic/prepare-dotty branch July 29, 2020 15:18
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