Skip to content

Commit 800aa0e

Browse files
committed
Rename NamedTuple.FieldsOf --> NamedTuple.From
1 parent 9ba1325 commit 800aa0e

File tree

7 files changed

+16
-20
lines changed

7 files changed

+16
-20
lines changed

compiler/src/dotty/tools/dotc/core/Definitions.scala

+4-4
Original file line numberDiff line numberDiff line change
@@ -1322,8 +1322,8 @@ class Definitions {
13221322
final def isCompiletime_S(sym: Symbol)(using Context): Boolean =
13231323
sym.name == tpnme.S && sym.owner == CompiletimeOpsIntModuleClass
13241324

1325-
final def isNamedTuple_FieldsOf(sym: Symbol)(using Context): Boolean =
1326-
sym.name == tpnme.FieldsOf && sym.owner == NamedTupleModule.moduleClass
1325+
final def isNamedTuple_From(sym: Symbol)(using Context): Boolean =
1326+
sym.name == tpnme.From && sym.owner == NamedTupleModule.moduleClass
13271327

13281328
private val compiletimePackageAnyTypes: Set[Name] = Set(
13291329
tpnme.Equals, tpnme.NotEquals, tpnme.IsConst, tpnme.ToString
@@ -1353,7 +1353,7 @@ class Definitions {
13531353
tpnme.Plus, tpnme.Length, tpnme.Substring, tpnme.Matches, tpnme.CharAt
13541354
)
13551355
private val compiletimePackageOpTypes: Set[Name] =
1356-
Set(tpnme.S, tpnme.FieldsOf)
1356+
Set(tpnme.S, tpnme.From)
13571357
++ compiletimePackageAnyTypes
13581358
++ compiletimePackageIntTypes
13591359
++ compiletimePackageLongTypes
@@ -1366,7 +1366,7 @@ class Definitions {
13661366
compiletimePackageOpTypes.contains(sym.name)
13671367
&& (
13681368
isCompiletime_S(sym)
1369-
|| isNamedTuple_FieldsOf(sym)
1369+
|| isNamedTuple_From(sym)
13701370
|| sym.owner == CompiletimeOpsAnyModuleClass && compiletimePackageAnyTypes.contains(sym.name)
13711371
|| sym.owner == CompiletimeOpsIntModuleClass && compiletimePackageIntTypes.contains(sym.name)
13721372
|| sym.owner == CompiletimeOpsLongModuleClass && compiletimePackageLongTypes.contains(sym.name)

compiler/src/dotty/tools/dotc/core/StdNames.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -361,8 +361,8 @@ object StdNames {
361361
val Eql: N = "Eql"
362362
val EnumValue: N = "EnumValue"
363363
val ExistentialTypeTree: N = "ExistentialTypeTree"
364-
val FieldsOf: N = "FieldsOf"
365364
val Flag : N = "Flag"
365+
val From: N = "From"
366366
val Ident: N = "Ident"
367367
val Import: N = "Import"
368368
val Literal: N = "Literal"

compiler/src/dotty/tools/dotc/core/TypeEval.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ object TypeEval:
146146
val constantType =
147147
if defn.isCompiletime_S(sym) then
148148
constantFold1(natValue, _ + 1)
149-
else if defn.isNamedTuple_FieldsOf(sym) then
149+
else if defn.isNamedTuple_From(sym) then
150150
fieldsOf
151151
else if owner == defn.CompiletimeOpsAnyModuleClass then name match
152152
case tpnme.Equals => constantFold2(constValue, _ == _)

docs/_docs/reference/experimental/named-tuples.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -100,19 +100,19 @@ The translation of named tuples to instances of `NamedTuple` is fixed by the spe
100100
- All tuple operations also work with named tuples "out of the box".
101101
- Macro libraries can rely on this expansion.
102102

103-
### The FieldsOf Type
103+
### The NamedTuple.From Type
104104

105105
The `NamedTuple` object contains a type definition
106106
```scala
107-
type FieldsOf[T] <: AnyNamedTuple
107+
type From[T] <: AnyNamedTuple
108108
```
109-
`FieldsOf` is treated specially by the compiler. When `FieldsOf` is applied to
109+
`From` is treated specially by the compiler. When `NamedTuple.From` is applied to
110110
an argument type that is an instance of a case class, the type expands to the named
111111
tuple consisting of all the fields of that case class. Here, fields means: elements of the first parameter section. For instance, assuming
112112
```scala
113113
case class City(zip: Int, name: String, population: Int)
114114
```
115-
then `FieldsOf[City]` is the named tuple
115+
then `NamedTuple.From[City]` is the named tuple
116116
```scala
117117
(zip: Int, name: String, population: Int)
118118
```

library/src/scala/NamedTuple.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ object NamedTuple:
175175
case true =>
176176
NamedTuple[Names[X], Tuple.Zip[DropNames[X], DropNames[Y]]]
177177

178-
type FieldsOf[T] <: AnyNamedTuple
178+
type From[T] <: AnyNamedTuple
179179

180180
end NamedTuple
181181

tests/neg/fieldsOf.scala

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
import NamedTuple.FieldsOf
2-
31
case class Person(name: String, age: Int)
42
class Anon(name: String, age: Int)
5-
def foo[T](): FieldsOf[T] = ???
3+
def foo[T](): NamedTuple.From[T] = ???
64

75
def test =
8-
var x: FieldsOf[Person] = ???
6+
var x: NamedTuple.From[Person] = ???
97
x = foo[Person]() // ok
108
x = foo[Anon]() // error
119
x = foo() // error

tests/pos/fieldsOf.scala

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
import NamedTuple.FieldsOf
2-
31
case class Person(name: String, age: Int)
42

5-
type PF = FieldsOf[Person]
3+
type PF = NamedTuple.From[Person]
64

7-
def foo[T]: FieldsOf[T] = ???
5+
def foo[T]: NamedTuple.From[T] = ???
86

97
class Anon(name: String, age: Int)
108

119
def test =
12-
var x: FieldsOf[Person] = ???
10+
var x: NamedTuple.From[Person] = ???
1311
val y: (name: String, age: Int) = x
1412
x = y
1513
x = foo[Person]

0 commit comments

Comments
 (0)