Skip to content

Commit b0bf4df

Browse files
committed
Temporarily allow delegate for implicit function types and closures
We have a migration problem for implicit function types and closures. We cannot go in one step from ``` given A => B given (x: A) => B ``` to ``` (given A) => B (given x: A) => B ``` because this becomes ambiguous inside parentheses. We have to migrate using intermediate steps: 1. re-allow delegate instead of given for these types and closures 2. disallow given in the old position, and migrate all code over to delegate 3. allow given in the new position. 4. disallow delegate and migrate all code over to given in the new position.
1 parent a6ecc14 commit b0bf4df

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2486,6 +2486,7 @@ object Parsers {
24862486
case ABSTRACT => Mod.Abstract()
24872487
case FINAL => Mod.Final()
24882488
case IMPLICIT => Mod.Implicit()
2489+
case IMPLIED => Mod.Given()
24892490
case GIVEN => Mod.Given()
24902491
case ERASED => Mod.Erased()
24912492
case LAZY => Mod.Lazy()
@@ -2589,11 +2590,11 @@ object Parsers {
25892590
* FunTypeMods ::= { ‘erased’ | ‘given’}
25902591
*/
25912592
val closureMods: BitSet =
2592-
if allowOldGiven then BitSet(GIVEN, IMPLICIT, ERASED)
2593+
if allowOldGiven then BitSet(GIVEN, IMPLIED, IMPLICIT, ERASED)
25932594
else BitSet(IMPLICIT)
25942595

25952596
val funTypeMods: BitSet =
2596-
if allowOldGiven then BitSet(GIVEN, ERASED)
2597+
if allowOldGiven then BitSet(GIVEN, IMPLIED, ERASED)
25972598
else BitSet()
25982599

25992600
/** Wrap annotation or constructor in New(...).<init> */

tests/new/test.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
trait T {
22
object O
3+
4+
type U = delegate Int => Int
5+
type V = given Int => Int
6+
7+
val u = delegate (x: Int) => x
8+
val v = given (x: Int) => x
39
}

0 commit comments

Comments
 (0)