This repository was archived by the owner on Mar 27, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Bump to dotty 0.27.0-RC1 #67
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5e8cee9
Bump Dotty version
eloots b5be787
Bump Dotty version to 0.27.0-RC1
eloots e120621
Organise code snippets
eloots 3851967
Fix extension method syntax/Fix indentation
eloots 0784941
Switch to Significant Indentation Based Syntax
eloots 32be237
Remove option for .sbtopts that will be deprecated in the future
eloots File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
...bstractions/src/main/scala/org/lunatech/dotty/extensionmethods/CollectiveExtensions.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
9 changes: 9 additions & 0 deletions
9
...-abstractions/src/main/scala/org/lunatech/dotty/extensionmethods/ExtensionOperators.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
21 changes: 21 additions & 0 deletions
21
...al-abstractions/src/main/scala/org/lunatech/dotty/extensionmethods/GenericExtension.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...ons/src/main/scala/org/lunatech/dotty/extensionmethods/ScopeExtensionMethods.worksheet.sc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
14 changes: 0 additions & 14 deletions
14
code-snippets/src/main/scala/org/lunatech/dotty/extensionmethods/CollectiveExtensions.scala
This file was deleted.
Oops, something went wrong.
24 changes: 0 additions & 24 deletions
24
code-snippets/src/main/scala/org/lunatech/dotty/extensionmethods/ExtensionInstance.scala
This file was deleted.
Oops, something went wrong.
11 changes: 0 additions & 11 deletions
11
code-snippets/src/main/scala/org/lunatech/dotty/extensionmethods/ExtensionOperators.scala
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
code-snippets/src/main/scala/org/lunatech/dotty/extensionmethods/GenericExtension.scala
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
-J-Xmx4G | ||
-J-XX:+CMSClassUnloadingEnabled | ||
-J-Xss4M | ||
-Duser.timezone=GMT |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.