Skip to content
This repository was archived by the owner on Mar 27, 2025. It is now read-only.

Bump to dotty 0.27.0-RC1 #67

Merged
merged 6 commits into from
Sep 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ collectedLogs.zip
.bloop/
.metals/
.swp
project/metals.sbt
**/project/metals.sbt

# sbt specific
.cache/
Expand Down
6 changes: 3 additions & 3 deletions code-snippets/build.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
val dottyVersion = "0.24.0-RC1"
val dottyVersion = "0.27.0-RC1"

Global / onChangedBuildSource := ReloadOnSourceChanges

Expand All @@ -9,8 +9,8 @@ lazy val `dotty-snippets` = project
name := "dotty-simple",
version := "0.1.0",

ThisBuild / scalaVersion := dottyVersion,
//ThisBuild / scalaVersion := dottyLatestNightlyBuild.get,
//ThisBuild / scalaVersion := dottyVersion,
ThisBuild / scalaVersion := dottyLatestNightlyBuild.get,

libraryDependencies += "com.novocode" % "junit-interface" % "0.11" % "test"
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.lunatech.dotty.extensionmethods.collective

extension (i: Int)
def isEven: Boolean = i % 2 == 0

def unary_! : Int = -i

def square : Int = i * i

extension [T](xs: List[T]):
def second: T = xs.tail.head
def third: T = xs.tail.second

@main def collective() =
println(List(1,2,3).second)
println(! 5)
println(5.isEven)
println(5.square)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.lunatech.dotty.extensionmethods

extension (a: String) def < (b: String): Boolean = a.compareTo(b) < 0

extension (a: Int) def +++: (b: List[Int]) = a::b

@main def extensionOperators() =
println("abc" < "pqr") // true
println(1 +++: List(2,3,4)) // val lst: List[Int] = List(1, 2, 3, 4)
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.lunatech.dotty.extensionmethods

extension [T](xs: List[T])
def second =
xs.tail.head

extension [T](xs: List[List[T]])
def flattened =
xs.foldLeft[List[T]](Nil)(_ ++ _)

extension [T: Numeric](x: T)
def + (y: T): T =
summon[Numeric[T]].plus(x, y)

def [T: Numeric](x: T) - (y: T) = summon[Numeric[T]].plus(x, y)

case class Circle(x: Double, y: Double, radius: Double)
def (c: Circle).circumference: Double = c.radius * math.Pi * 2

@main def circles() =
println(s"Circle: ${Circle(1.0, 2.0, 4).circumference}")
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package org.lunatech.dotty.extensionmethods

trait IntOps {
def (i: Int).isEven: Boolean = i % 2 == 0
extension (i: Int):
def isEven: Boolean = i % 2 == 0

def (i: Int).unary_! : Int = -i
}

object IntOperations {
def unary_! : Int = -i

// 1. An extension method is applicable if it is visible under a simple name,
// by being defined or inherited or imported in a scope enclosing the application
Expand All @@ -17,10 +14,7 @@ object IntOperations {
// we could define this object as `IntOperations extends IntOps`.
// A more elegant way to bring `IntOps` to the context is by using a `given`

given IntOps
@main def show(): Unit =
println(2.isEven) // true
println(!5) // -5

@main def show(): Unit = {
println(2.isEven) // true
println(!5) // -5
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
trait IntOps:
extension (i: Int) def isZero: Boolean = i == 0

extension (i: Int) def safeMod(x: Int): Option[Int] =
// extension method defined in same scope IntOps
if x.isZero then None
else Some(i % x)

object IntOpsEx extends IntOps:
extension (i: Int) def safeDiv(x: Int): Option[Int] =
// extension method brought into scope via inheritance from IntOps
if x.isZero then None
else Some(i / x)

object SafeDiv:
import IntOpsEx._ // brings safeDiv and safeMod into scope

extension (i: Int) def divide(d: Int) : Option[(Int, Int)] =
// extension methods imported and thus in scope
(i.safeDiv(d), i.safeMod(d)) match
case (Some(d), Some(r)) => Some((d, r))
case _ => None

val d1 = 25.divide(3)
val d2 = 25.divide(0)

SafeDiv.d1
SafeDiv.d2

given IntOps

20.safeMod(0)
20.safeMod(3)

extension [T](xs: List[List[T]])
def flatten: List[T] = xs.foldLeft(Nil: List[T])(_ ++ _)

given [T: Ordering] as Ordering[List[T]]:
override def compare(l1: List[T], l2: List[T]): Int = 1
extension (xs: List[T])
def < (ys: List[T]): Boolean = summon[Ordering[T]].lt(xs.head, ys.head)


// extension method available since it is in the implicit scope of List[List[Int]]
List(List(1, 2), List(3, 4)).flatten

// extension method available since it is in the given Ordering[List[T]],
// which is itself in the implicit scope of List[Int]
List(1, 2) < List(3)
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,15 @@ object Scala3OpaqueTypeAliasesDefinitions {
def apply(d: Double): Miles = d
}

extension {
def (a: Kilometres) + (b: Kilometres): Kilometres = a + b
def (km: Kilometres).toMiles: Miles = km / 1.6
}
extension (a: Kilometres):
def +(b: Kilometres): Kilometres = a + b
def toMiles: Miles = a / 1.6

extension {
def (a: Miles) + (b: Miles): Miles = a + b
def (miles: Miles).toKm: Kilometres = miles * 1.6
}

extension (a: Miles):
// def +(b: Miles): Miles = a + b
def toKm: Kilometres = a * 1.6


}

Expand Down
2 changes: 1 addition & 1 deletion code-snippets/project/metals.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// DO NOT EDIT! This file is auto-generated.
// This file enables sbt-bloop to create bloop config files.

addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.4.0-RC1-229-b7c15aa9")
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.4.3-31-b16d7e50")
4 changes: 4 additions & 0 deletions code-snippets/project/project/metals.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// DO NOT EDIT! This file is auto-generated.
// This file enables sbt-bloop to create bloop config files.

addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.4.3-31-b16d7e50")
4 changes: 4 additions & 0 deletions code-snippets/project/project/project/metals.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// DO NOT EDIT! This file is auto-generated.
// This file enables sbt-bloop to create bloop config files.

addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.4.3-31-b16d7e50")

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

8 changes: 0 additions & 8 deletions code-snippets/src/test/scala/Test1.scala

This file was deleted.

1 change: 0 additions & 1 deletion exercises/.sbtopts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
-J-Xmx4G
-J-XX:+CMSClassUnloadingEnabled
-J-Xss4M
-Duser.timezone=GMT
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ class SudokuProgressTracker private (
case NewUpdatesInFlight(updateCount) =>
trackProgress(updatesInFlight + updateCount)
case msg: SudokuDetailState =>
context.log.error("Received unexpected message in state 'trackProgress': {}", msg)
// context.log.error("Received unexpected message in state 'trackProgress': {}", msg)
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we can add an issue in this repo that is a TODO to go back and fix this when the dotty issue (scala/scala3#9688) is addressed? And the issue in our course repo can link the issue in the dotty repo. And then in the code you can add a link to the new issue (otherwise the commented out code isn't really useful by itself)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call!

Will do as otherwise, there's the risk that we forget to revert the workaround when it's no longer needed.

context.log.error(s"Received unexpected message in state 'trackProgress': ${msg}")
Behaviors.same
}

Expand All @@ -58,7 +59,8 @@ class SudokuProgressTracker private (
case detail: SudokuDetailState =>
collectEndState(remainingRows = remainingRows - 1, detail +: endState)
case msg: NewUpdatesInFlight =>
context.log.error("Received unexpected message in state 'collectEndState': {}", msg)
// context.log.error("Received unexpected message in state 'collectEndState': {}", msg)
context.log.error(s"Received unexpected message in state 'collectEndState': ${msg}")
Behaviors.same
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ class SudokuSolver private (context: ActorContext[SudokuSolver.Command],
progressTracker ! SudokuProgressTracker.NewUpdatesInFlight(rowUpdates.size)
processRequest(Some(sender), System.currentTimeMillis())
case unexpectedMsg =>
context.log.error("Received an unexpected message in 'idle' state: {}", unexpectedMsg)
// context.log.error("Received an unexpected message in 'idle' state: {}", unexpectedMsg)
context.log.error(s"Received an unexpected message in 'idle' state: ${unexpectedMsg}")
Behaviors.same

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ class SudokuProgressTracker private (
case NewUpdatesInFlight(updateCount) =>
trackProgress(updatesInFlight + updateCount)
case msg: SudokuDetailState =>
context.log.error("Received unexpected message in state 'trackProgress': {}", msg)
// context.log.error("Received unexpected message in state 'trackProgress': {}", msg)
context.log.error(s"Received unexpected message in state 'trackProgress': ${msg}")
Behaviors.same
}

Expand All @@ -58,7 +59,8 @@ class SudokuProgressTracker private (
case detail: SudokuDetailState =>
collectEndState(remainingRows = remainingRows - 1, detail +: endState)
case msg: NewUpdatesInFlight =>
context.log.error("Received unexpected message in state 'collectEndState': {}", msg)
// context.log.error("Received unexpected message in state 'collectEndState': {}", msg)
context.log.error(s"Received unexpected message in state 'collectEndState': ${msg}")
Behaviors.same
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ class SudokuSolver private (context: ActorContext[SudokuSolver.Command],
progressTracker ! SudokuProgressTracker.NewUpdatesInFlight(rowUpdates.size)
processRequest(Some(sender), System.currentTimeMillis())
case unexpectedMsg =>
context.log.error("Received an unexpected message in 'idle' state: {}", unexpectedMsg)
// context.log.error("Received an unexpected message in 'idle' state: {}", unexpectedMsg)
context.log.error(s"Received an unexpected message in 'idle' state: ${unexpectedMsg}")
Behaviors.same

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ class SudokuProgressTracker private (
case NewUpdatesInFlight(updateCount) =>
trackProgress(updatesInFlight + updateCount)
case msg: SudokuDetailState =>
context.log.error("Received unexpected message in state 'trackProgress': {}", msg)
// context.log.error("Received unexpected message in state 'trackProgress': {}", msg)
context.log.error(s"Received unexpected message in state 'trackProgress': ${msg}")
Behaviors.same
}

Expand All @@ -58,7 +59,8 @@ class SudokuProgressTracker private (
case detail: SudokuDetailState =>
collectEndState(remainingRows = remainingRows - 1, detail +: endState)
case msg: NewUpdatesInFlight =>
context.log.error("Received unexpected message in state 'collectEndState': {}", msg)
// context.log.error("Received unexpected message in state 'collectEndState': {}", msg)
context.log.error(s"Received unexpected message in state 'collectEndState': ${msg}")
Behaviors.same
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ class SudokuSolver private (context: ActorContext[SudokuSolver.Command],
progressTracker ! SudokuProgressTracker.NewUpdatesInFlight(rowUpdates.size)
processRequest(Some(sender), System.currentTimeMillis())
case unexpectedMsg =>
context.log.error("Received an unexpected message in 'idle' state: {}", unexpectedMsg)
// context.log.error("Received an unexpected message in 'idle' state: {}", unexpectedMsg)
context.log.error(s"Received an unexpected message in 'idle' state: ${unexpectedMsg}")
Behaviors.same

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import org.lunatechlabs.dotty.sudoku.{ SudokuProblemSender, SudokuSolver, Sudoku
import scala.io.StdIn
import scala.Console.{ GREEN, RESET }

object Main {
object Main:
def apply(): Behavior[NotUsed] =
Behaviors.setup { context =>
val sudokuSolverSettings = SudokuSolverSettings("sudokusolver.conf")
Expand All @@ -44,16 +44,13 @@ object Main {
Behaviors.stopped
}
}
}

object SudokuSolverMain {
object SudokuSolverMain:

def main(args: Array[String]): Unit = {
def main(args: Array[String]): Unit =

val system = ActorSystem[NotUsed](Main(), "sudoku-solver-system")

println(s"${GREEN}Hit RETURN to stop solver${RESET}")
StdIn.readLine()
system.terminate()
}
}
Loading