From 2cd9ab6202b4e9bb7bd36b44a9acfa460cb3939d Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 29 May 2017 18:11:12 +0200 Subject: [PATCH 1/5] Add section on dropping DelayedInit --- docs/docs/reference/delaydInit.md | 26 ++++++++++++++++++++++++++ docs/sidebar.yml | 4 ++++ 2 files changed, 30 insertions(+) create mode 100644 docs/docs/reference/delaydInit.md diff --git a/docs/docs/reference/delaydInit.md b/docs/docs/reference/delaydInit.md new file mode 100644 index 000000000000..1c5abeb2504f --- /dev/null +++ b/docs/docs/reference/delaydInit.md @@ -0,0 +1,26 @@ +--- +layout: doc-page +title: Dropped: Delayedinit +--- + +The special handling of the `DelayedInit` trait is no longer +supported. + +One consequence is that the `App` class, which used `DelayedInit` is +now partially broken. You can still use `App` for an easy and concise +way to set up a main program. Example: + + object HelloWorld extends App { + println("Hello, world!") + } + +However, the code is now run in the initializer of the object, which on +some JVM's means that it will only be interpreted. So, better not use it +for benchmarking! Also, if you want to access the command line arguments, +you need to use an explicit `main` method for that. + + object Hello extends App { + def main(args: Array[String]) = + println(s"Hello, ${args(0)}") + } + diff --git a/docs/sidebar.yml b/docs/sidebar.yml index da5adf040a4a..673aa384ded6 100644 --- a/docs/sidebar.yml +++ b/docs/sidebar.yml @@ -3,6 +3,10 @@ sidebar: url: blog/index.html - title: Reference subsection: + - title: Dropped Features + subsection: + - title: DelayedInit + - url: docs/reference/delayed-init.md - title: Implicit Function Types url: docs/reference/implicit-function-types.md - title: Intersection types From 88b0f0077e0dc63cdcf96742bbfb08da00232548 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 29 May 2017 18:14:17 +0200 Subject: [PATCH 2/5] Move delayedInit.md to dropped subdirectory --- docs/docs/reference/{delaydInit.md => dropped/delayedInit.md} | 0 docs/sidebar.yml | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename docs/docs/reference/{delaydInit.md => dropped/delayedInit.md} (100%) diff --git a/docs/docs/reference/delaydInit.md b/docs/docs/reference/dropped/delayedInit.md similarity index 100% rename from docs/docs/reference/delaydInit.md rename to docs/docs/reference/dropped/delayedInit.md diff --git a/docs/sidebar.yml b/docs/sidebar.yml index 673aa384ded6..81978bc40374 100644 --- a/docs/sidebar.yml +++ b/docs/sidebar.yml @@ -6,7 +6,7 @@ sidebar: - title: Dropped Features subsection: - title: DelayedInit - - url: docs/reference/delayed-init.md + url: docs/reference/dropped/delayed-init.md - title: Implicit Function Types url: docs/reference/implicit-function-types.md - title: Intersection types From 15e4e13453c20b4ef5c38675f83f47c712a0bb3c Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 29 May 2017 18:22:15 +0200 Subject: [PATCH 3/5] Add section for dropped feature "macros" --- docs/docs/reference/dropped/macros.md | 13 +++++++++++++ docs/sidebar.yml | 2 ++ 2 files changed, 15 insertions(+) create mode 100644 docs/docs/reference/dropped/macros.md diff --git a/docs/docs/reference/dropped/macros.md b/docs/docs/reference/dropped/macros.md new file mode 100644 index 000000000000..3db506bf3a67 --- /dev/null +++ b/docs/docs/reference/dropped/macros.md @@ -0,0 +1,13 @@ +--- +layout: doc-page +title: Dropped: Macros +--- + +The previous, experimental macro system has been dropped. Instead, +there is a cleaner, more restricted system based on two complementary +concepts: `inline` and `meta`. + +`inline` has been [implemented](../inline.md) in Dotty. + +`meta` is worked on in the separate [Scalameta](http://scalameta.org) project + diff --git a/docs/sidebar.yml b/docs/sidebar.yml index 81978bc40374..ecf7a376b057 100644 --- a/docs/sidebar.yml +++ b/docs/sidebar.yml @@ -7,6 +7,8 @@ sidebar: subsection: - title: DelayedInit url: docs/reference/dropped/delayed-init.md + - title: Macros + url: docs/reference/dropped/macros.md - title: Implicit Function Types url: docs/reference/implicit-function-types.md - title: Intersection types From fff1ca299b30c567b0052ce723f71c785fe52f5a Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 29 May 2017 18:35:40 +0200 Subject: [PATCH 4/5] Fix typo and add test --- docs/docs/reference/dropped/delayedInit.md | 2 +- tests/run/delayedInit.scala | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 tests/run/delayedInit.scala diff --git a/docs/docs/reference/dropped/delayedInit.md b/docs/docs/reference/dropped/delayedInit.md index 1c5abeb2504f..a087c24c50f6 100644 --- a/docs/docs/reference/dropped/delayedInit.md +++ b/docs/docs/reference/dropped/delayedInit.md @@ -19,7 +19,7 @@ some JVM's means that it will only be interpreted. So, better not use it for benchmarking! Also, if you want to access the command line arguments, you need to use an explicit `main` method for that. - object Hello extends App { + object Hello { def main(args: Array[String]) = println(s"Hello, ${args(0)}") } diff --git a/tests/run/delayedInit.scala b/tests/run/delayedInit.scala new file mode 100644 index 000000000000..e03a8f0764ff --- /dev/null +++ b/tests/run/delayedInit.scala @@ -0,0 +1,3 @@ +object Test extends App { + println("Hello World: ") +} From 28f2f23e468c01a9545dbc830dfe882c69f4bb42 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 29 May 2017 19:41:07 +0200 Subject: [PATCH 5/5] Add sections on dropped features --- .../docs/reference/dropped/class-shadowing.md | 29 ++++++++ .../reference/dropped/early-initializers.md | 11 +++ .../reference/dropped/existential-types.md | 33 +++++++++ docs/docs/reference/dropped/limit22.md | 13 ++++ .../reference/dropped/procedure-syntax.md | 19 +++++ .../docs/reference/dropped/type-projection.md | 15 ++++ docs/docs/reference/dropped/xml.md | 9 +++ docs/sidebar.yml | 72 ++++++++++++------- tests/neg/class-shadowing.scala | 7 ++ 9 files changed, 182 insertions(+), 26 deletions(-) create mode 100644 docs/docs/reference/dropped/class-shadowing.md create mode 100644 docs/docs/reference/dropped/early-initializers.md create mode 100644 docs/docs/reference/dropped/existential-types.md create mode 100644 docs/docs/reference/dropped/limit22.md create mode 100644 docs/docs/reference/dropped/procedure-syntax.md create mode 100644 docs/docs/reference/dropped/type-projection.md create mode 100644 docs/docs/reference/dropped/xml.md create mode 100644 tests/neg/class-shadowing.scala diff --git a/docs/docs/reference/dropped/class-shadowing.md b/docs/docs/reference/dropped/class-shadowing.md new file mode 100644 index 000000000000..a0be5985626f --- /dev/null +++ b/docs/docs/reference/dropped/class-shadowing.md @@ -0,0 +1,29 @@ +--- +layout: doc-page +title: Dropped: Class Shadowing +--- + +Scala so far allowed patterns like this: + + class Base { + class Ops { ... } + } + + class Sub extends Base { + class Ops { ... } + } + +Dotty rejects this with the error message: + + 6 | class Ops { } + | ^ + |class Ops cannot have the same name as class Ops in class Base -- class definitions cannot be overridden + +The issue is that the two `Ops` classes _look_ like one overrides the +other, but classes in Scala cannot be overridden. To keep things clean +(and its internal operations conistent) the Dotty compiler forces you +to rename the inner classes so that their names are different. + + + + diff --git a/docs/docs/reference/dropped/early-initializers.md b/docs/docs/reference/dropped/early-initializers.md new file mode 100644 index 000000000000..0ccea31bcbe4 --- /dev/null +++ b/docs/docs/reference/dropped/early-initializers.md @@ -0,0 +1,11 @@ +--- +layout: doc-page +title: Dropped: Early Initializers +--- + +Early initializers of the form + + class C extends { ... } with SuperClass ... + +have been dropped. They were rarely used, and mostly to compensate for the lack of +[trait parameters](../trait-parameters.md), which are now directly supported in Dotty. diff --git a/docs/docs/reference/dropped/existential-types.md b/docs/docs/reference/dropped/existential-types.md new file mode 100644 index 000000000000..f4f3a469f6a7 --- /dev/null +++ b/docs/docs/reference/dropped/existential-types.md @@ -0,0 +1,33 @@ +--- +layout: doc-page +title: Dropped: Existential Types +--- + +Existential types using `forSome` have been dropped. The reasons for dropping them were: + + - Existential types violate a type soundness principle on which DOT + and Dotty are constructed. That principle says that every the + prefix (`p`, respectvely `S`) of a type selection `p.T` or `S#T` + must either come from a value constructed at runtime or refer to a + type that is known to have only good bounds. + + - Existential types create many difficult feature interactions + with other Scala constructs. + + - Existential types have large overlap with path-dependent types, + so the gain of having them is relatively minor. + +Existential types that can be expressed using only wildcards (but not +`forSome`) are still supported, but are treated as refined types. +For instance, the type + + Map[_ <: AnyRef, Int] + +is treated as the type `Map`, where the first type parameter +is upper-bounded by `AnyRef` and the second type parameter is an alias +of `Int`. + +When reading classfiles compiled with _scalac_, Dotty will do a best +effort to approximate existential types with its own types. It will +issue a warning is a precise emulation is not possible. + diff --git a/docs/docs/reference/dropped/limit22.md b/docs/docs/reference/dropped/limit22.md new file mode 100644 index 000000000000..7a7cbf931bf9 --- /dev/null +++ b/docs/docs/reference/dropped/limit22.md @@ -0,0 +1,13 @@ +--- +layout: doc-page +title: Dropped: Limit 22 +--- + +The limit of 22 for the maximal number of parameters of function types +has been dropped. Functions can now have an arbitrary number of +parameters. Functions beyond Function22 are represented with a new trait +`scala.FunctionXXL`. + +The limit of 22 for the size of tuples is about to be dropped. Tuples +will in the future be represented by an HList-like structure which can +be arbitrarily large. diff --git a/docs/docs/reference/dropped/procedure-syntax.md b/docs/docs/reference/dropped/procedure-syntax.md new file mode 100644 index 000000000000..8cf1fdc375fd --- /dev/null +++ b/docs/docs/reference/dropped/procedure-syntax.md @@ -0,0 +1,19 @@ +--- +layout: doc-page +title: Dropped: Procedure Syntax +--- + +Procedure syntax + + def f() { ... } + +has been dropped. You need to write one of the following instead: + + def f() = { ... } + def f(): Unit = { ... } + +Dotty will accept the old syntax under the `-language:Scala2` option. +If the `-migration` option is set, it can even rewrite old syntax to new. +The [ScalaFix](https://scalacenter.github.io/scalafix/) tool also +can rewrite procedure syntax to make it Dotty-compatible. + diff --git a/docs/docs/reference/dropped/type-projection.md b/docs/docs/reference/dropped/type-projection.md new file mode 100644 index 000000000000..1e2e986d5e9c --- /dev/null +++ b/docs/docs/reference/dropped/type-projection.md @@ -0,0 +1,15 @@ +--- +layout: doc-page +title: Dropped: General Type Projection +--- + +Scala so far allowed general type projection `T#A` where `T` is an arbitrary type +and `A` names a type member of `T`. + +Dotty allows this only if `T` is a class type. The change was made because +unrestricted type projection is [unsound](https://github.com/lampepfl/dotty/issues/1050). + +The restriction rule out the [type-level encoding of compbinator + calculus](https://michid.wordpress.com/2010/01/29/scala-type-level-encoding-of-the-ski-calculus/). It also rules out the previous encodings of type +lambdas using structural types with projection as application. Type + lambdas are now [directly supported](../type-lambdas.md) in Dotty. \ No newline at end of file diff --git a/docs/docs/reference/dropped/xml.md b/docs/docs/reference/dropped/xml.md new file mode 100644 index 000000000000..6e261ef96d10 --- /dev/null +++ b/docs/docs/reference/dropped/xml.md @@ -0,0 +1,9 @@ +--- +layout: doc-page +title: Dropped: XML Literals +--- + +XML Literals are still supported, but will be dropped in the near future, to +be replaced with XML string interpolation + + xml""" ... """ diff --git a/docs/sidebar.yml b/docs/sidebar.yml index ecf7a376b057..e68696a85ca8 100644 --- a/docs/sidebar.yml +++ b/docs/sidebar.yml @@ -3,38 +3,58 @@ sidebar: url: blog/index.html - title: Reference subsection: - - title: Dropped Features + - title: New Types subsection: - - title: DelayedInit - url: docs/reference/dropped/delayed-init.md - - title: Macros - url: docs/reference/dropped/macros.md - - title: Implicit Function Types - url: docs/reference/implicit-function-types.md - - title: Intersection types - url: docs/reference/intersection-types.html - - title: Union types - url: docs/reference/union-types.html - - title: Type lambdas - url: docs/reference/type-lambdas.html + - title: Implicit Function Types + url: docs/reference/implicit-function-types.md + - title: Intersection types + url: docs/reference/intersection-types.html + - title: Union types + url: docs/reference/union-types.html + - title: Type lambdas + url: docs/reference/type-lambdas.html + - title: Enums + subsection: + - title: Enumerations + url: docs/reference/enums.html + - title: Algebraic Data Types + url: docs/reference/adts.html + - title: Translation + url: docs/reference/desugarEnums.html - title: Trait Parameters url: docs/reference/trait-parameters.html - - title: Enumerations - url: docs/reference/enums.html - - title: Algebraic Data Types - url: docs/reference/adts.html - - title: Enum Translation - url: docs/reference/desugarEnums.html - - title: Multiversal Equality + -title: Multiversal Equality url: docs/reference/multiversal-equality.html - - title: By-Name Implicits - url: docs/reference/implicit-by-name-parameters.htmldocs/reference/implicit-by-name-parameters.html - - title: Auto Parameter Tupling - url: docs/reference/auto-parameter-tupling.html - - title: Named Type Arguments - url: docs/reference/named-typeargs.html - title: Inline url: docs/reference/inline.html + - title: Smaller Changes + subsection: + - title: By-Name Implicits + url: docs/reference/implicit-by-name-parameters.html + - title: Auto Parameter Tupling + url: docs/reference/auto-parameter-tupling.html + - title: Named Type Arguments + url: docs/reference/named-typeargs.html + - title: Dropped Features + subsection: + - title: DelayedInit + url: docs/reference/dropped/delayed-init.md + - title: Macros + url: docs/reference/dropped/macros.md + - title: Existential Types + url: docs/reference/dropped/existential-types.md + - title: Type Projection + url: docs/reference/dropped/type-projection.md + - Procedure Syntax + url: docs/reference/dropped/procedure-syntax.md + - title: Early Initializers + url: docs/reference/dropped/early-initializers.md + - title: Class Shadowing + url: docs/reference/dropped/class-shadowing.md + - title: Limit 22 + url: docs/reference/dropped/limit22.md + - title: XML literals + url: docs/reference/dropped/xml.md - title: Usage subsection: - title: sbt-projects diff --git a/tests/neg/class-shadowing.scala b/tests/neg/class-shadowing.scala new file mode 100644 index 000000000000..127c17d65509 --- /dev/null +++ b/tests/neg/class-shadowing.scala @@ -0,0 +1,7 @@ + class Base { + class Ops { } + } + + class Sub extends Base { + class Ops { } // error: cannot override + }