Skip to content

Update sbt to 1.4.4 #41

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
wants to merge 59 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
50b341e
-
mslinn Nov 18, 2019
00f5015
-
mslinn Nov 18, 2019
6cf73f0
-
mslinn Nov 18, 2019
08c5ddf
-
mslinn Nov 18, 2019
5740b2e
-
mslinn Nov 18, 2019
7541819
-
mslinn Nov 18, 2019
9e331c5
-
mslinn Nov 18, 2019
41f40a3
-
mslinn Nov 18, 2019
0bb2a9c
-
mslinn Nov 18, 2019
64fb2d4
-
mslinn Nov 19, 2019
8514a35
-
mslinn Nov 19, 2019
d6df577
-
mslinn Nov 19, 2019
b91bb4f
-
mslinn Nov 19, 2019
b8666ee
-
mslinn Nov 19, 2019
281733d
-
mslinn Nov 19, 2019
6aeb463
Update build.properties
mslinn Nov 24, 2019
36457ba
-
mslinn Nov 25, 2019
142d08b
-
mslinn Nov 25, 2019
163776a
-
mslinn Nov 25, 2019
a75eb03
-
mslinn Nov 25, 2019
e9e3d66
-
mslinn Nov 25, 2019
be497ca
-
mslinn Nov 26, 2019
62e3175
-
mslinn Nov 26, 2019
004f113
-
mslinn Nov 26, 2019
8097548
-
mslinn Nov 26, 2019
6f5dd69
-
mslinn Nov 26, 2019
d746979
-
mslinn Nov 26, 2019
c0fb069
-
mslinn Nov 26, 2019
366a242
-
mslinn Nov 26, 2019
a7a6568
-
mslinn Nov 26, 2019
abd66bf
-
mslinn Nov 26, 2019
2b733ab
-
mslinn Nov 26, 2019
477c53b
-
mslinn Nov 26, 2019
9f894dc
-
mslinn Nov 26, 2019
9990ba0
-
mslinn Nov 26, 2019
139dd8e
-
mslinn Nov 26, 2019
c65727b
-
mslinn Nov 26, 2019
706296d
-
mslinn Nov 26, 2019
67649f8
-
mslinn Nov 26, 2019
4019e5c
-
mslinn Nov 26, 2019
60aac65
-
mslinn Nov 26, 2019
849bc03
-
mslinn Nov 26, 2019
0ecd5a2
-
mslinn Nov 27, 2019
90332ac
-
mslinn Nov 27, 2019
e80c0e4
-
mslinn Nov 27, 2019
0691fee
-
mslinn Nov 27, 2019
7e20fff
-
mslinn Nov 27, 2019
a306ccc
-
mslinn Nov 27, 2019
ad71ce3
-
mslinn Nov 27, 2019
0c21c60
-
mslinn Nov 27, 2019
406166a
-
mslinn Nov 27, 2019
c183838
-
mslinn Nov 27, 2019
cb20d0d
-
mslinn Nov 27, 2019
5e33baf
-
mslinn Nov 27, 2019
de3ab8a
-
mslinn Nov 27, 2019
5cb4e2f
-
mslinn Nov 27, 2019
d14cc12
-
mslinn Nov 27, 2019
641bfa6
-
mslinn Nov 28, 2019
5b27ab7
Update sbt to 1.4.4
scala-steward Dec 2, 2020
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
8 changes: 0 additions & 8 deletions .travis.yml

This file was deleted.

64 changes: 40 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,44 @@
# Example sbt project that compiles using Dotty
# Example sbt Project that Compiles Using Dotty

[![Build Status](https://travis-ci.org/lampepfl/dotty-example-project.svg?branch=master)](https://travis-ci.org/lampepfl/dotty-example-project)
I (Mike Slinn, founder of [ScalaCourses.com](https://www.ScalaCourses.com)) fixed many significant bugs in the [upstream project](https://github.com/lampepfl/dotty-example-project) and added code examples for new major features that were missing.

## Usage

This is a normal sbt project, you can compile code with `sbt compile` and run it
with `sbt run`, `sbt console` will start a Dotty REPL.
This is a normal sbt project.
You can compile code with `sbt compile` and run it
with `sbt run` or `sbt runMain <entryPoint>`.
`sbt console` will start a Dotty REPL.

You can also execute just one example from the `sbt console` by evaluating the `test` method, for example we can run `Typeclasses.test`:

```
$ sbt console
scala> Typeclasses.test
sum("a", "b", "c"): abc
```

If compiling this example project fails, you probably have a global sbt plugin
that does not work with dotty, try to disable all plugins in
`~/.sbt/1.0/plugins` and `~/.sbt/1.0`.
that does not work with dotty; disable all plugins in
`~/.sbt/1.0/plugins` and `~/.sbt/1.0` by renaming those directories to something else.

### IDE support
## IDE Support

Dotty comes built-in with IDE support, to try it out see
> Dotty comes built-in with IDE support, to try it out see
http://dotty.epfl.ch/docs/usage/ide-support.html

## Making a new Dotty project
The fastest way to start a new Dotty project is to use one of the following templates:
* [Simple Dotty project](https://github.com/lampepfl/dotty.g8)
* [Dotty project that cross-compiles with Scala 2](https://github.com/lampepfl/dotty-cross.g8)
Meh, not so much.
I found Atom with sbt running in a shell under `platformio-ide-terminal` worked best.

## Making a New Dotty Project
> The fastest way to start a new Dotty project is to use one of the following templates:
> * [Simple Dotty project](https://github.com/lampepfl/dotty.g8)
> * [Dotty project that cross-compiles with Scala 2](https://github.com/lampepfl/dotty-cross.g8)

## Using Dotty in an existing project
I am not a fan of `giter8`.
There is no reason to introduce yet another obscure language.
[Try dottyTemplate](https://github.com/mslinn/dottyTemplate) instead.

## Using Dotty in An Existing Project

You will need to make the following adjustments to your build:

Expand All @@ -30,31 +47,30 @@ You will need to make the following adjustments to your build:
addSbtPlugin("ch.epfl.lamp" % "sbt-dotty" % "0.3.4")
```

### project/build.properties
### `project/build.properties`
```scala
sbt.version=1.2.8
```

Older versions of sbt are not supported.

Versions of sbt older than 1.2.8 are not supported.
Versions 1.3.3 and 1.3.4 do not work properly with Dotty.

### build.sbt
### `build.sbt`
Any version number that starts with `0.` is automatically recognized as Dotty by
the `sbt-dotty` plugin, you don't need to set up anything:

```scala
scalaVersion := "0.20.0-RC1"
```

#### Nightly builds
### Nightly Builds
If the latest release of Dotty is missing a bugfix or feature you need, you may
wish to use a nightly build. Look at the bottom of
https://repo1.maven.org/maven2/ch/epfl/lamp/dotty_0.18/ to find the version
number for the latest nightly build. Alternatively, you can set `scalaVersion :=
dottyLatestNightlyBuild.get` to always use the latest nightly build of dotty.

## Getting your project to compile with Dotty

## Compiling Scala 2 Projects with Dotty
When porting an existing project, it's a good idea to start out with the Scala 2
compatibility mode (note that this mode affects typechecking and thus may
prevent some valid Dotty code from compiling) by adding to your `build.sbt`:
Expand All @@ -66,9 +82,11 @@ scalacOptions ++= { if (isDotty.value) Seq("-language:Scala2") else Nil }
Using the `isDotty` setting ensures that this option will only be set when
compiling with Dotty.

A tool to port code from Scala 2.x to Dotty is currently in development at
> A tool to port code from Scala 2.x to Dotty is currently in development at
https://github.com/scalacenter/scalafix

Actually, the truth is `scalafix` has not had any work done on it in a long time, and there is no indication when this important project will get the attention it deserves. I'm concerned that history will repeat itself and we'll get a last-minute hack job.

If your build contains dependencies that have only been published for Scala 2.x,
you may be able to get them to work on Dotty by replacing:

Expand All @@ -93,6 +111,4 @@ Alternatively, to set this setting on all your dependencies, you can use:
```

## Discuss

Feel free to come chat with us on the
[Dotty gitter](http://gitter.im/lampepfl/dotty)!
Chat on the [Dotty gitter](http://gitter.im/lampepfl/dotty) channel.
16 changes: 7 additions & 9 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
lazy val root = project
.in(file("."))
.settings(
name := "dotty-example-project",
description := "Example sbt project that compiles using Dotty",
version := "0.1.0",

scalaVersion := "0.20.0-RC1"
)
description := "Example sbt project that compiles using Dotty"
logBuffered in Test := false
logLevel := Level.Warn
logLevel in test := Level.Info
name := "dotty-example-project"
scalaVersion := "0.20.0-RC1"
version := "0.1.0"
4 changes: 3 additions & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
sbt.version=1.2.8
# Sbt versions older than 1.1.4 are not supported with Dotty.
# Sbt versions 1.3.3 and 1.3.4 do not work properly with Dotty.
sbt.version=1.4.4
26 changes: 8 additions & 18 deletions src/main/scala/AutoParamTupling.scala
Original file line number Diff line number Diff line change
@@ -1,24 +1,14 @@

/**
* Automatic Tupling of Function Params: https://dotty.epfl.ch/docs/reference/other-new-features/auto-parameter-tupling.html
*/
object AutoParamTupling {

def test: Unit = {

/**
* In order to get thread safety, you need to put @volatile before lazy vals.
* https://dotty.epfl.ch/docs/reference/changed-features/lazy-vals.html
*/
/** Automatic Tupling of Function Params: https://dotty.epfl.ch/docs/reference/other-new-features/auto-parameter-tupling.html */
@main def AutoParamTupling =
def test: Unit =
/** In order to get thread safety, you need to put @volatile before lazy vals.
* https://dotty.epfl.ch/docs/reference/changed-features/lazy-vals.html */
@volatile lazy val xs: List[String] = List("d", "o", "t", "t", "y")

/**
* Current behaviour in Scala 2.12.2 :
/** Current behaviour in Scala 2.12 :
* error: missing parameter type
* Note: The expected type requires a one-argument function accepting a 2-Tuple.
* Consider a pattern matching anonymous function, `{ case (s, i) => ... }`
*/
* Consider a pattern matching anonymous function, `{ case (s, i) => ... }` */
xs.zipWithIndex.map((s, i) => println(s"$i: $s"))

}
}
test
48 changes: 0 additions & 48 deletions src/main/scala/ContextQueries.scala

This file was deleted.

45 changes: 45 additions & 0 deletions src/main/scala/ContextQueries1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@

import scala.concurrent.{ExecutionContext, Future}
import scala.util.Try

/** Context Queries (Formerly known as Implicit Function Types):
* - Implicit functions are functions that only have implicit parameters.
* - Their types are implicit function types.
* - http://dotty.epfl.ch/docs/reference/contextual/implicit-function-types.html,
* - Old syntax: https://www.scala-lang.org/blog/2016/12/07/implicit-function-types.html */
@main def ContextQueries1 =
object context with
// type alias Contextual
type Contextual[T] = (given ExecutionContext) => T

// sum is expanded to sum(x, y)(ctx)
def asyncSum(x: Int, y: Int): Contextual[Future[Int]] = Future(x + y)

def asyncMult(x: Int, y: Int)
(given ctx: ExecutionContext): Contextual[Future[Int]] =
Future(x * y)

object parse with
type Parseable[T] = (given Delegates.StringParser[T]) => Try[T]

def sumStrings(x: String, y: String): Parseable[Int] = {
val parser = implicitly[Delegates.StringParser[Int]]
val tryA = parser.parse(x)
val tryB = parser.parse(y)

for {
a <- tryA
b <- tryB
} yield a + b
}

def test: Unit =
import ExecutionContext.Implicits.global

context.asyncSum(3, 4).foreach(x => println("asyncSum: " + x))
context.asyncMult(3, 4).foreach(x => println("asyncMult: " + x))

println("""parse.sumStrings("3", "4"): """ + parse.sumStrings("3", "4"))
println("""parse.sumStrings("3", "a"): """ + parse.sumStrings("3", "a"))

test
25 changes: 25 additions & 0 deletions src/main/scala/ContextQueries2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/** This example combines opaque aliases, implicit function types, and extension methods to provide
* a zero-overhead abstraction at runtime.
* See http://dotty.epfl.ch/docs/reference/contextual/implicit-function-types.html#example-postconditions */
object PostConditions
opaque type WrappedResult[T] = T

def result[T](given r: WrappedResult[T]): T = r

/** This extension method accepts an implicit function type called `condition`,
* which receives the given instance of type `WrappedResult[T]``.
* The given `WrappedResult` instance is passed to the result method.
* `WrappedResult` is an opaque type alias, so its values need not be boxed or unboxed.
* Because `ensuring` is added as an extension method, its argument also does not need boxing. */
def [T](x: T) ensuring(condition: (given WrappedResult[T]) => Boolean): T =
assert(condition(given x))
x

@main def ContextQueries2 =
import PostConditions.{ensuring, result}

def test: Unit =
val s = List(1, 2, 3).sum.ensuring(result == 6)
println("Yes, the list sums to 6.")

test
43 changes: 15 additions & 28 deletions src/main/scala/Conversion.scala
Original file line number Diff line number Diff line change
@@ -1,37 +1,24 @@
import scala.language.implicitConversions

/**
* Conversions: http://dotty.epfl.ch/docs/reference/contextual/conversions.html
*/
object Conversion {

case class IntWrapper(a: Int) extends AnyVal
case class DoubleWrapper(b: Double) extends AnyVal

def convert[T, U](x: T)(given converter: Conversion[T, U]): U = converter(x)

given IntWrapperToDoubleWrapper: Conversion[IntWrapper, DoubleWrapper] = new Conversion[IntWrapper, DoubleWrapper] {
override def apply(i: IntWrapper): DoubleWrapper = new DoubleWrapper(i.a.toDouble)
}

def useConversion(given f: Conversion[IntWrapper, DoubleWrapper]) = {
case class IntWrapper(a: Int) extends AnyVal
case class DoubleWrapper(b: Double) extends AnyVal

/** Conversions: http://dotty.epfl.ch/docs/reference/contextual/conversions.html */
@main def Conversion =
def convert[T, U](t: T)
(given converter: Conversion[T, U]): U = converter(t)

given IntWrapperToDoubleWrapper: Conversion[IntWrapper, DoubleWrapper] =
new Conversion[IntWrapper, DoubleWrapper] with
override def apply(i: IntWrapper): DoubleWrapper = new DoubleWrapper(i.a.toDouble)

def useConversion(given f: Conversion[IntWrapper, DoubleWrapper]) =
val y: IntWrapper = new IntWrapper(4)
val x: DoubleWrapper = y
x
}

/* Not working anymore.
def useConversion(implicit f: A => B) = {
val y: A = ...
val x: B = a // error under Dotty
}
*/

def test: Unit = {
def test: Unit =
println(useConversion)
println(convert(new IntWrapper(42)))
}



}
test
35 changes: 35 additions & 0 deletions src/main/scala/Delegates.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import scala.util.{Success, Try}

/** Delegates (formerly known as Implied Instances):
* - https://dotty.epfl.ch/docs/reference/contextual/delegates.html
* - https://dotty.epfl.ch/docs/reference/contextual/derivation.html*/
object Delegates with
sealed trait StringParser[A]
def parse(s: String): Try[A]

object StringParser with
def apply[A](given parser: StringParser[A]): StringParser[A] = parser

private def baseParser[A](f: String ⇒ Try[A]): StringParser[A] =
new StringParser[A] {
override def parse(s: String): Try[A] = f(s)
}

given stringParser: StringParser[String] = baseParser(Success(_))
given intParser: StringParser[Int] = baseParser(s ⇒ Try(s.toInt))

given optionParser[A](given parser: => StringParser[A]): StringParser[Option[A]] =
new StringParser[Option[A]] {
override def parse(s: String): Try[Option[A]] = s match
case "" ⇒ Success(None) // implicit parser not used.
case str ⇒ parser.parse(str).map(Some(_)) // implicit parser is evaluated here
}

def test: Unit =
val spoi = implicitly[StringParser[Option[Int]]]
println(spoi.parse("21"))
println(spoi.parse(""))
println(spoi.parse("21a"))
println(StringParser.optionParser[Int].parse("42"))

test
Loading