Skip to content
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
57 changes: 30 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
# Example sbt project that compiles using Dotty
# Example sbt project that compiles using Scala 3

[![Build Status](https://travis-ci.com/scala/scala3-example-project.svg?branch=master)](https://travis-ci.com/scala/scala3-example-project)

## 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.
with `sbt run`, `sbt console` will start a Scala 3 REPL.

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
that does not work with Scala 3, try to disable all plugins in
`~/.sbt/1.0/plugins` and `~/.sbt/1.0`.

### IDE support

Dotty comes built-in with IDE support, to try it out see
http://dotty.epfl.ch/docs/usage/ide-support.html
Scala 3 comes built-in with IDE support, to try it out see
[IDE support for Scala 3](http://dotty.epfl.ch/docs/usage/ide-support.html)

## Making a new Dotty project
## Making a new Scala 3 project

The fastest way to start a new Dotty project is to use one of the following templates:
The fastest way to start a new Scala 3 project is to use one of the following templates:

* [Simple Dotty project](https://github.com/scala/scala3.g8)
* [Dotty project that cross-compiles with Scala 2](https://github.com/scala/scala3-cross.g8)
* [Minimal Scala 3 project](https://github.com/scala/scala3.g8)
* [Scala 3 project that cross-compiles with Scala 2](https://github.com/scala/scala3-cross.g8)

## Using Dotty in an existing project
## Using Scala 3 in an existing project

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

Expand All @@ -33,6 +33,10 @@ You will need to make the following adjustments to your build:
addSbtPlugin("ch.epfl.lamp" % "sbt-dotty" % "0.5.3")
```

Here, _dotty_ is the project name for technologies that are considered for inclusion in Scala 3.
Since the development of Scala 3 is not done, the word _dotty_ and _Dotty_ are still can be seen
in some names of Scala 3 related tools, sbt plugins, etc.

### project/build.properties

```scala
Expand All @@ -43,39 +47,38 @@ You must use sbt 1.4 or newer; older versions of sbt are not supported.

### 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:
Set up the Scala 3 version:

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

#### 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/org/scala-lang/scala3-compiler_3.0.0-RC1/ 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.
If the latest release of Scala 3 is missing a bugfix or feature you need, you may
wish to use a nightly build. Look at the bottom of the list of
[releases](https://repo1.maven.org/maven2/org/scala-lang/scala3-compiler_3.0.0-RC1/)
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 Scala 3.

## Getting your project to compile with Dotty
## Getting your project to compile with Scala 3

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`:
prevent some valid Scala 3 code from compiling) by adding to your `build.sbt`:

```scala
scalacOptions ++= { if (isDotty.value) Seq("-source:3.0-migration") else Nil }
```

Using the `isDotty` setting ensures that this option will only be set when
compiling with Dotty. For more information on the `-source` flag, see
http://dotty.epfl.ch/docs/usage/language-versions.html, for more information on
migrating to Scala 3 see [the migration
guide](https://github.com/scalacenter/scala-3-migration-guide).
compiling with Scala 3. For more information on the `-source` flag, see
[language versions](http://dotty.epfl.ch/docs/usage/language-versions.html);
for more information on migrating to Scala 3, see
[the migration guide](https://github.com/scalacenter/scala-3-migration-guide).

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:
you may be able to get them to work on Scala 3 by replacing:

```scala
libraryDependencies += "a" %% "b" % "c"
Expand All @@ -88,8 +91,8 @@ by:
```

This will have no effect when compiling with Scala 2.x, but when compiling
with Dotty this will change the cross-version to a Scala 2.x one. This
works because Dotty is currently retro-compatible with Scala 2.x.
with Scala 3 this will change the cross-version to a Scala 2.x one. This
works because Scala 3 is currently retro-compatible with Scala 2.x.

Alternatively, to set this setting on all your dependencies, you can use:

Expand All @@ -100,4 +103,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)!
[Scala 3 gitter](http://gitter.im/lampepfl/dotty)!
2 changes: 1 addition & 1 deletion src/main/scala/Conversion.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ object Conversion {
/* Not working anymore.
def useConversion(implicit f: A => B) = {
val y: A = ...
val x: B = a // error under Dotty
val x: B = a // error under Scala 3
}
*/

Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/TraitParams.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ object TraitParams {
class A extends Base("Hello")
class B extends Base("Dotty!")

// Union types only exist in Dotty, so there's no chance that this will accidentally be compiled with Scala 2
// Union types only exist in Scala 3, so there's no chance that this will accidentally be compiled with Scala 2
private def printMessages(msgs: (A | B)*) = println(msgs.map(_.msg).mkString(" "))

def test(): Unit = {
printMessages(new A, new B)

// Sanity check the classpath: this won't run if the dotty jar is not present.
// Sanity check the classpath: this won't run if the Scala 3 jar is not present.
val x: Int => Int = z => z
x(1)
}
Expand Down