Skip to content

Commit 87cdbc8

Browse files
committed
Make named tuples a standard feature
- Deprecate experimental language import - Make named tuple features conditional on -source >= 3.6 instead - Make the NamedTuple object non-experimental. - Move NamedTuple it to src-bootstrapped since it relies on clause interleaving which is only standard in 3.6 as well. - Drop the experimental.namedTuple import from tests
1 parent 56a384f commit 87cdbc8

36 files changed

+70
-112
lines changed

compiler/src/dotty/tools/dotc/config/Feature.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ object Feature:
3434
val pureFunctions = experimental("pureFunctions")
3535
val captureChecking = experimental("captureChecking")
3636
val into = experimental("into")
37-
val namedTuples = experimental("namedTuples")
3837
val modularity = experimental("modularity")
3938
val betterMatchTypeExtractors = experimental("betterMatchTypeExtractors")
4039
val quotedPatternsWithPolymorphicFunctions = experimental("quotedPatternsWithPolymorphicFunctions")
@@ -66,7 +65,6 @@ object Feature:
6665
(pureFunctions, "Enable pure functions for capture checking"),
6766
(captureChecking, "Enable experimental capture checking"),
6867
(into, "Allow into modifier on parameter types"),
69-
(namedTuples, "Allow named tuples"),
7068
(modularity, "Enable experimental modularity features"),
7169
(betterMatchTypeExtractors, "Enable better match type extractors"),
7270
(betterFors, "Enable improvements in `for` comprehensions")

compiler/src/dotty/tools/dotc/config/ScalaSettingsProperties.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ object ScalaSettingsProperties:
2525
ScalaRelease.values.toList.map(_.show)
2626

2727
def supportedSourceVersions: List[String] =
28-
SourceVersion.values.toList.map(_.toString)
28+
(SourceVersion.values.toList.diff(SourceVersion.illegalSourceVersionNames)).toList.map(_.toString)
2929

3030
def supportedLanguageFeatures: List[ChoiceWithHelp[String]] =
3131
Feature.values.map((n, d) => ChoiceWithHelp(n.toString, d))

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ object Parsers {
651651
else leading :: Nil
652652

653653
def maybeNamed(op: () => Tree): () => Tree = () =>
654-
if isIdent && in.lookahead.token == EQUALS && in.featureEnabled(Feature.namedTuples) then
654+
if isIdent && in.lookahead.token == EQUALS && sourceVersion.isAtLeast(`3.6`) then
655655
atSpan(in.offset):
656656
val name = ident()
657657
in.nextToken()
@@ -2137,7 +2137,7 @@ object Parsers {
21372137

21382138
if namedOK && isIdent && in.lookahead.token == EQUALS then
21392139
commaSeparated(() => namedArgType())
2140-
else if tupleOK && isIdent && in.lookahead.isColon && in.featureEnabled(Feature.namedTuples) then
2140+
else if tupleOK && isIdent && in.lookahead.isColon && sourceVersion.isAtLeast(`3.6`) then
21412141
commaSeparated(() => namedElem())
21422142
else
21432143
commaSeparated(() => argType())

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
789789
def tryNamedTupleSelection() =
790790
val namedTupleElems = qual.tpe.widenDealias.namedTupleElementTypes
791791
val nameIdx = namedTupleElems.indexWhere(_._1 == selName)
792-
if nameIdx >= 0 && Feature.enabled(Feature.namedTuples) then
792+
if nameIdx >= 0 && sourceVersion.isAtLeast(`3.6`) then
793793
typed(
794794
untpd.Apply(
795795
untpd.Select(untpd.TypedSplice(qual), nme.apply),

library/src/scala/NamedTuple.scala renamed to library/src-bootstrapped/scala/NamedTuple.scala

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package scala
2-
import scala.language.experimental.clauseInterleaving
3-
import annotation.experimental
42
import compiletime.ops.boolean.*
53

6-
@experimental
74
object NamedTuple:
85

96
/** The type to which named tuples get mapped to. For instance,
@@ -133,7 +130,6 @@ object NamedTuple:
133130
end NamedTuple
134131

135132
/** Separate from NamedTuple object so that we can match on the opaque type NamedTuple. */
136-
@experimental
137133
object NamedTupleDecomposition:
138134
import NamedTuple.*
139135
extension [N <: Tuple, V <: Tuple](x: NamedTuple[N, V])

library/src/scala/runtime/stdLibPatches/language.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ object language:
9797
* @see [[https://dotty.epfl.ch/docs/reference/experimental/named-tuples]]
9898
*/
9999
@compileTimeOnly("`namedTuples` can only be used at compile time in import statements")
100+
@deprecated("The experimental.namedTuples language import is no longer needed since the feature is now standard", since = "3.6")
100101
object namedTuples
101102

102103
/** Experimental support for new features for better modularity, including

presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionSuite.scala

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1988,8 +1988,7 @@ class CompletionSuite extends BaseCompletionSuite:
19881988

19891989
@Test def `namedTuple completions` =
19901990
check(
1991-
"""|import scala.language.experimental.namedTuples
1992-
|import scala.NamedTuple.*
1991+
"""|import scala.NamedTuple.*
19931992
|
19941993
|val person = (name = "Jamie", city = "Lausanne")
19951994
|
@@ -2000,8 +1999,7 @@ class CompletionSuite extends BaseCompletionSuite:
20001999

20012000
@Test def `Selectable with namedTuple Fields member` =
20022001
check(
2003-
"""|import scala.language.experimental.namedTuples
2004-
|import scala.NamedTuple.*
2002+
"""|import scala.NamedTuple.*
20052003
|
20062004
|class NamedTupleSelectable extends Selectable {
20072005
| type Fields <: AnyNamedTuple
@@ -2091,7 +2089,7 @@ class CompletionSuite extends BaseCompletionSuite:
20912089
|""".stripMargin
20922090
)
20932091

2094-
@Test def `conflict-3` =
2092+
@Test def `conflict-3` =
20952093
check(
20962094
"""|package a
20972095
|object A {

tests/neg/i20517.check

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
-- [E007] Type Mismatch Error: tests/neg/i20517.scala:10:43 ------------------------------------------------------------
2-
10 | def dep(foo: Foo[Any]): From[foo.type] = (elem = "") // error
3-
| ^^^^^^^^^^^
4-
| Found: (elem : String)
5-
| Required: NamedTuple.From[(foo : Foo[Any])]
6-
|
7-
| longer explanation available when compiling with `-explain`
1+
-- [E007] Type Mismatch Error: tests/neg/i20517.scala:9:43 -------------------------------------------------------------
2+
9 | def dep(foo: Foo[Any]): From[foo.type] = (elem = "") // error
3+
| ^^^^^^^^^^^
4+
| Found: (elem : String)
5+
| Required: NamedTuple.From[(foo : Foo[Any])]
6+
|
7+
| longer explanation available when compiling with `-explain`

tests/neg/i20517.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import scala.language.experimental.namedTuples
21
import NamedTuple.From
32

43
case class Foo[+T](elem: T)

tests/neg/named-tuple-selectable.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import scala.language.experimental.namedTuples
2-
31
class FromFields extends Selectable:
42
type Fields = (i: Int)
53
def selectDynamic(key: String) =

0 commit comments

Comments
 (0)