Skip to content

Commit 482dfeb

Browse files
authored
Spec: Rewrite the type system fundamentals. (#17447)
There are two fundamental differences between the type sytems of Scala 2 and 3, which made a fundamental rewrite desirable: - Scala 2 defines path-dependent types in terms of type projections, whereas Scala 3 is path-dependent first, and has not general type projects. - Scala 2 has ad hoc higher-kinded type parameters and polymorphic type aliases, whereas Scala 3 has first-class type lambdas and is fundamentally higher kinded. We therefore rewrite the entire type system section of the spec to be higher-kinded and path-dependent first. In the process, we also revise refined types to better fit the path-dependent nature. I (sjrd) took the liberty to add myself as a contributor in the index page of the spec, as I believe this constitutes a fundamental contribution to the language specification.
2 parents f821d53 + 254f23e commit 482dfeb

File tree

6 files changed

+932
-490
lines changed

6 files changed

+932
-490
lines changed

docs/_docs/internals/syntax.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,6 @@ SimpleType1 ::= id
201201
Singleton ::= SimpleRef
202202
| SimpleLiteral
203203
| Singleton ‘.’ id
204-
Singletons ::= Singleton { ‘,’ Singleton }
205204
FunArgType ::= [`erased`] Type
206205
| [`erased`] ‘=>’ Type PrefixOp(=>, t)
207206
FunArgTypes ::= FunArgType { ‘,’ FunArgType }
@@ -357,8 +356,8 @@ ClsParam ::= {Annotation}
357356
[{Modifier} (‘val’ | ‘var’) | ‘inline’] Param
358357
359358
DefParamClauses ::= DefParamClause { DefParamClause } -- and two DefTypeParamClause cannot be adjacent
360-
DefParamClause ::= DefTypeParamClause
361-
| DefTermParamClause
359+
DefParamClause ::= DefTypeParamClause
360+
| DefTermParamClause
362361
| UsingParamClause
363362
TypelessClauses ::= TypelessClause {TypelessClause}
364363
TypelessClause ::= DefTermParamClause

docs/_docs/reference/new-types/intersection-types-spec.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,10 @@ A & B <: B A & B <: A
4646
In another word, `A & B` is the same type as `B & A`, in the sense that the two types
4747
have the same values and are subtypes of each other.
4848

49-
If `C` is a type constructor, then `C[A] & C[B]` can be simplified using the following three rules:
49+
If `C` is a co- or contravariant type constructor, then `C[A] & C[B]` can be simplified using the following rules:
5050

5151
- If `C` is covariant, `C[A] & C[B] ~> C[A & B]`
5252
- If `C` is contravariant, `C[A] & C[B] ~> C[A | B]`
53-
- If `C` is non-variant, emit a compile error
5453

5554
When `C` is covariant, `C[A & B] <: C[A] & C[B]` can be derived:
5655

docs/_spec/02-identifiers-names-and-scopes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ In that case, the type of ´x´ is the type of the referenced entity.
5353

5454
A reference to a qualified (type- or term-) identifier ´e.x´ refers to the member of the type ´T´ of ´e´ which has the name ´x´ in the same namespace as the identifier.
5555
It is an error if ´T´ is not a [value type](03-types.html#value-types).
56-
The type of ´e.x´ is the member type of the referenced entity in ´T´.
56+
The type of ´e.x´ is specified as a [type designator](03-types.html#type-designators).
5757

5858
Binding precedence implies that the way source is bundled in files affects name resolution.
5959
In particular, imported names have higher precedence than names, defined in other files, that might otherwise be visible because they are defined in either the current package or an enclosing package.

0 commit comments

Comments
 (0)