Skip to content

Commit ccc064c

Browse files
committed
Merge branch 'change-overload-lambda' of https://github.com/dotty-staging/dotty into change-overload-lambda
# Conflicts: # docs/docs/reference/changed-features/overload-resolution.md # tests/run/overloads.check # tests/run/overloads.scala
2 parents cd9e7e1 + c6a561c commit ccc064c

File tree

5 files changed

+159
-0
lines changed

5 files changed

+159
-0
lines changed

docs/docs/reference/effects.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
layout: doc-page
3+
title: "Effects"
4+
---
5+
6+
```scala
7+
package scala {
8+
type Pure
9+
type Impure <: Pure
10+
type CanThrow[-Exc <: Throwable] >: Impure
11+
12+
def Try[T, Exc](body: implicit CanThrow[Exc] => T)(catcher: Exc => T): T = {
13+
try {
14+
implicit val canThrow: CanThrow[Exc] = Effect.isImpure
15+
body
16+
}
17+
catch {
18+
case exc: Exc => catcher(exc)
19+
}
20+
}
21+
}
22+
```
23+
24+
```scala
25+
package scala
26+
object Effect {
27+
val isImpure: Impure
28+
val canThrowNPE: CanThrow[NullPointerException]
29+
val canThrow: CanThrow[Throwable]
30+
}
31+
```
32+
33+
import Effect.{_ => _}

docs/docs/reference/export.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
layout: doc-page
3+
title: "Export"
4+
---
5+
6+
### Syntax changes:
7+
8+
```
9+
TemplateStat ::= ...
10+
| Export
11+
Export ::= ‘export’ ImportExprs
12+
```
13+
14+
Similarly to imports, an export with several parts
15+
16+
```
17+
export iexpr_1, ..., iexpr_n`
18+
```
19+
20+
is a shorthand for
21+
22+
```
23+
export iexpr_1
24+
...
25+
export iexpr_n`
26+
```
27+
28+
To explain how export clauses influence type checking we explain in the following one possible scheme. As always, compilers are free to pick a different scheme if the observable results are the same.
29+
30+
An export `export prefix . selectors` in a template is legal if `prefix` is a path that refers either to a member of the template or to a globally accessible object.
31+
Such an export generates a public "export" member with a compiler-generated name that's inaccessible to user programs and globally unique, and a special type
32+
33+
ExportType(PT, E)
34+
35+
where `E` is the export clause itself and `PT` is the type of `prefix`. The `PT` part of an `ExportType` behaves as usual with regards to type maps such as substitution or as-seen-from.
36+
37+
When typing a selection `p.m`, if `p` does not have a member named `m`, the following adaptation is tried before searching for an implicit conversion of `p`:
38+
39+
Let `es` be all the export members of `p`. We first search all explicit exports and then, if that returns no results, all wildcard exports for a match with `m`, exactly as it is done when processing import statements. If there are several matching members they all must have the same prefix type `PT`, or an ambiguity error is reported. Otherwise, pick an arbitary element of the set of matching members, say member `e` defined in class `C` with type `ExportType(PT, export q . ss)`. The selection `p.m` is then rewritten to one of the following alternatives, depending on the form of `q`.
40+
41+
- If `q` refers to a globally accessible object: `q.m`
42+
- If `q` is of the form `C.this . q_1 . ... q _n`: `p . q_1 . ... . q_n . m`
43+
44+
45+
46+
47+
48+
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
layout: doc-page
3+
title: "Export"
4+
---
5+
6+
### Syntax changes:
7+
8+
```
9+
TemplateStat ::= ...
10+
| Export
11+
Export ::= ‘export’ ImportExprs
12+
```
13+
14+
Similarly to imports, an export with several parts
15+
16+
```
17+
export iexpr_1, ..., iexpr_n`
18+
```
19+
20+
is a shorthand for
21+
22+
```
23+
export iexpr_1
24+
...
25+
export iexpr_n`
26+
```
27+
28+
To explain how export clauses influence type checking we explain in the following one possible scheme. As always, compilers are free to pick a different scheme if the observable results are the same.
29+
30+
An export `export prefix . selectors` in a template is legal if `prefix` is a path that refers either to a member of the template or to a globally accessible object.
31+
Such an export generates a public "export" member with a compiler-generated name that's inaccessible to user programs and globally unique, and a special type
32+
33+
ExportType(PT, E)
34+
35+
where `E` is the export clause itself and `PT` is the type of `prefix`. The `PT` part of an `ExportType` behaves as usual with regards to type maps such as substitution or as-seen-from.
36+
37+
When typing a selection `p.m`, if `p` does not have a member named `m`, the following adaptation is tried before searching for an implicit conversion of `p`:
38+
39+
Let `es` be all the export members of `p`. We first search all explicit exports and then, if that returns no results, all wildcard exports for a match with `m`, exactly as it is done when processing import statements. If there are several matching members they all must have the same prefix type `PT`, or an ambiguity error is reported. Otherwise, pick an arbitary element of the set of matching members, say member `e` defined in class `C` with type `ExportType(PT, export q . ss)`. The selection `p.m` is then rewritten to one of the following alternatives, depending on the form of `q`.
40+
41+
- If `q` refers to a globally accessible object: `q.m`
42+
- If `q` is of the form `C.this . q_1 . ... q _n`: `p . q_1 . ... . q_n . m`
43+
44+
45+
46+
47+
48+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
object Test {
2+
type StringToInt[T] = T match {
3+
case String => Int
4+
case Any => T // case t => t would be nice see (2) above
5+
}
6+
7+
implicitly[StringToInt[String] =:= String]
8+
implicitly[StringToInt[String] =:= Int]
9+
}

tests/pending/pos/i5535.scala

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
object Test {
2+
// The identity on types of the form N | P[a, P[b, ... P[z, N]]]
3+
type Nested[X, P[_, _], N] = X match {
4+
case N => N
5+
case P[a, b] => P[a, Nested[b, P, N]]
6+
}
7+
8+
// Type bound:
9+
// Recursion limit exceeded.
10+
// Maybe there is an illegal cyclic reference?
11+
def p1[T <: Nested[T, Tuple2, Unit]](t: T): T = t
12+
p1(())
13+
p1((23, ()))
14+
p1(("foo", (23, ())))
15+
16+
// Type constraint: OK
17+
def p2[T](t: T)(erased implicit ev: T <:< Nested[T, Tuple2, Unit]): T = t
18+
p2(())
19+
p2((23, ()))
20+
p2(("foo", (23, ())))
21+
}

0 commit comments

Comments
 (0)