Skip to content

Commit 3e7955e

Browse files
committed
Make NamedTupls an experimental feature again
[Cherry-picked a4ea8bf][modified]
1 parent 7debedf commit 3e7955e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+150
-91
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ object Feature:
3434
val pureFunctions = experimental("pureFunctions")
3535
val captureChecking = experimental("captureChecking")
3636
val into = experimental("into")
37+
val namedTuples = experimental("namedTuples")
3738
val modularity = experimental("modularity")
3839
val betterMatchTypeExtractors = experimental("betterMatchTypeExtractors")
3940
val quotedPatternsWithPolymorphicFunctions = experimental("quotedPatternsWithPolymorphicFunctions")
@@ -65,6 +66,7 @@ object Feature:
6566
(pureFunctions, "Enable pure functions for capture checking"),
6667
(captureChecking, "Enable experimental capture checking"),
6768
(into, "Allow into modifier on parameter types"),
69+
(namedTuples, "Allow named tuples"),
6870
(modularity, "Enable experimental modularity features"),
6971
(betterMatchTypeExtractors, "Enable better match type extractors"),
7072
(betterFors, "Enable improvements in `for` comprehensions")

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 && sourceVersion.isAtLeast(`3.6`) then
654+
if isIdent && in.lookahead.token == EQUALS && in.featureEnabled(Feature.namedTuples) then
655655
atSpan(in.offset):
656656
val name = ident()
657657
in.nextToken()
@@ -2166,7 +2166,7 @@ object Parsers {
21662166

21672167
if namedOK && isIdent && in.lookahead.token == EQUALS then
21682168
commaSeparated(() => namedArgType())
2169-
else if tupleOK && isIdent && in.lookahead.isColon && sourceVersion.isAtLeast(`3.6`) then
2169+
else if tupleOK && isIdent && in.lookahead.isColon && in.featureEnabled(Feature.namedTuples) then
21702170
commaSeparated(() => namedElem())
21712171
else
21722172
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 && sourceVersion.isAtLeast(`3.6`) then
792+
if nameIdx >= 0 && Feature.enabled(Feature.namedTuples) then
793793
typed(
794794
untpd.Apply(
795795
untpd.Select(untpd.TypedSplice(qual), nme.apply),

docs/_docs/reference/other-new-features/named-tuples.md renamed to docs/_docs/reference/experimental/named-tuples.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
---
22
layout: doc-page
33
title: "Named Tuples"
4-
nightlyOf: https://docs.scala-lang.org/scala3/reference/other-new-features/named-tuples.html
4+
nightlyOf: https://docs.scala-lang.org/scala3/reference/experimental/named-tuples.html
55
---
66

7-
Starting in Scala 3.6, the elements of a tuple can be named. Example:
7+
The elements of a tuple can now be named. Example:
88
```scala
99
type Person = (name: String, age: Int)
1010
val Bob: Person = (name = "Bob", age = 33)

docs/sidebar.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ subsection:
7272
- page: reference/other-new-features/export.md
7373
- page: reference/other-new-features/opaques.md
7474
- page: reference/other-new-features/opaques-details.md
75-
- page: reference/other-new-features/named-tuples.md
7675
- page: reference/other-new-features/open-classes.md
7776
- page: reference/other-new-features/parameter-untupling.md
7877
- page: reference/other-new-features/parameter-untupling-spec.md
@@ -159,6 +158,7 @@ subsection:
159158
- page: reference/experimental/cc.md
160159
- page: reference/experimental/purefuns.md
161160
- page: reference/experimental/tupled-function.md
161+
- page: reference/experimental/named-tuples.md
162162
- page: reference/experimental/modularity.md
163163
- page: reference/experimental/typeclasses.md
164164
- page: reference/experimental/runtimeChecked.md

library/src-bootstrapped/scala/NamedTuple.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package scala
2+
import annotation.experimental
23
import compiletime.ops.boolean.*
34

5+
@experimental
46
object NamedTuple:
57

68
/** The type to which named tuples get mapped to. For instance,
@@ -131,6 +133,7 @@ object NamedTuple:
131133
end NamedTuple
132134

133135
/** Separate from NamedTuple object so that we can match on the opaque type NamedTuple. */
136+
@experimental
134137
object NamedTupleDecomposition:
135138
import NamedTuple.*
136139
extension [N <: Tuple, V <: Tuple](x: NamedTuple[N, V])

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ 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")
101100
object namedTuples
102101

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

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

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

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

20002001
@Test def `Selectable with namedTuple Fields member` =
20012002
check(
2002-
"""|import scala.NamedTuple.*
2003+
"""|import scala.language.experimental.namedTuples
2004+
|import scala.NamedTuple.*
20032005
|
20042006
|class NamedTupleSelectable extends Selectable {
20052007
| type Fields <: AnyNamedTuple

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: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`
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`

tests/neg/i20517.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import scala.language.experimental.namedTuples
12
import NamedTuple.From
23

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

0 commit comments

Comments
 (0)