Skip to content

Commit c7f3b45

Browse files
committed
Drop restriction to 2nd order hk types
Allow hk type parameters to be higher kinded themselves.
1 parent 84a1a7a commit c7f3b45

File tree

6 files changed

+60
-12
lines changed

6 files changed

+60
-12
lines changed

docs/SyntaxSummary.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,8 @@ grammar.
225225
TypTypeParam ::= {Annotation} id [HkTypeParamClause] TypeBounds
226226

227227
HkTypeParamClause ::= `[' HkTypeParam {`,' HkTypeParam} `]'
228-
HkTypeParam ::= {Annotation} ['+' | `-'] (Id | `_') TypeBounds
228+
HkTypeParam ::= {Annotation} ['+' | `-'] (Id[HkTypeParamClause] | `_')
229+
TypeBounds
229230

230231
ClsParamClauses ::= {ClsParamClause} [[nl] `(' `implicit' ClsParams `)']
231232
ClsParamClause ::= [nl] `(' [ClsParams] ')'
@@ -280,7 +281,7 @@ grammar.
280281
DefDcl ::= DefSig [`:' Type] DefDef(_, name, tparams, vparamss, tpe, EmptyTree)
281282
DefSig ::= id [DefTypeParamClause] DefParamClauses
282283
TypeDcl ::= id [TypTypeParamClause] ['=' Type] TypeDefTree(_, name, tparams, tpt)
283-
| id [HkParamClause] TypeBounds TypeDefTree(_, name, tparams, bounds)
284+
| id [HkTypeParamClause] TypeBounds TypeDefTree(_, name, tparams, bounds)
284285

285286
Def ::= `val' PatDef
286287
| `var' VarDef

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1551,7 +1551,7 @@ object Parsers {
15511551
* TypTypeParam ::= {Annotation} Id [HkTypePamClause] TypeBounds
15521552
*
15531553
* HkTypeParamClause ::= `[' HkTypeParam {`,' HkTypeParam} `]'
1554-
* HkTypeParam ::= {Annotation} ['+' | `-'] (Id | _') TypeBounds
1554+
* HkTypeParam ::= {Annotation} ['+' | `-'] (Id[HkTypePamClause] | _') TypeBounds
15551555
*/
15561556
def typeParamClause(ownerKind: ParamOwner.Value): List[TypeDef] = inBrackets {
15571557
def typeParam(): TypeDef = {
@@ -1584,9 +1584,7 @@ object Parsers {
15841584
in.nextToken()
15851585
ctx.freshName(nme.USCORE_PARAM_PREFIX).toTypeName
15861586
}
1587-
val hkparams =
1588-
if (ownerKind == ParamOwner.TypeParam) Nil
1589-
else typeParamClauseOpt(ParamOwner.TypeParam)
1587+
val hkparams = typeParamClauseOpt(ParamOwner.TypeParam)
15901588
val bounds =
15911589
if (isConcreteOwner) typeParamBounds(name)
15921590
else typeBounds()

tests/disabled/not-representable/pos/t2066.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ trait A1 {
33
}
44

55
trait B1 extends A1 {
6-
override def f[T[_]] = ()
6+
override def f[T[+_]] = ()
77
}
88

99

@@ -12,12 +12,12 @@ trait A2 {
1212
}
1313

1414
trait B2 extends A2 {
15-
override def f[T[_]] = ()
15+
override def f[T[-_]] = ()
1616
}
1717

1818

1919
trait A3 {
20-
def f[T[X[_]]] = ()
20+
def f[T[X[+_]]] = ()
2121
}
2222

2323
trait B3 extends A3 {

tests/neg/t2994.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ object Naturals {
77
type a[s[_ <: NAT] <: NAT, z <: NAT] = z
88
}
99
final class SUCC[n <: NAT] extends NAT {
10-
type a[s[_ <: NAT] <: NAT, z <: NAT] = s[n#a[s, z]] // old-error: not a legal path
10+
type a[s[_ <: NAT] <: NAT, z <: NAT] = s[n#a[s, z]] // error: not a legal path
1111
}
1212
type _0 = ZERO
1313
type _1 = SUCC[_0]
@@ -20,8 +20,8 @@ object Naturals {
2020

2121
// crashes scala-2.8.0 beta1
2222
trait MUL[n <: NAT, m <: NAT] extends NAT {
23-
trait curry[n[_[_], _], s[_]] { type f[z <: NAT] = n[s, z] } // can't do double param lists: // error: `]' expected but `[` found. // error: wrong number of type arguments
24-
type a[s[_ <: NAT] <: NAT, z <: NAT] = n#a[curry[m#a, s]#f, z] // old-error: not a legal path // old-error: not a legal path
23+
trait curry[n[_[_], _], s[_]] { type f[z <: NAT] = n[s, z] }
24+
type a[s[_ <: NAT] <: NAT, z <: NAT] = n#a[curry[m#a, s]#f, z] // error: not a legal path // error: not a legal path
2525
}
2626

2727
}

tests/pos/t2066.scala

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
trait A1 {
2+
def f[T[+_]] = ()
3+
}
4+
5+
trait B1 extends A1 {
6+
override def f[T[+_]] = ()
7+
}
8+
9+
10+
trait A2 {
11+
def f[T[-_]] = ()
12+
}
13+
14+
trait B2 extends A2 {
15+
override def f[T[-_]] = ()
16+
}
17+
18+
19+
trait A3 {
20+
def f[T[X[+_]]] = ()
21+
}
22+
23+
trait B3 extends A3 {
24+
override def f[T[X[+_]]] = ()
25+
}

tests/pos/t2712-3.scala

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package test
2+
3+
object Test1 {
4+
class Foo[T, F[_]]
5+
def meh[M[_[_]], F[_]](x: M[F]): M[F] = x
6+
meh(new Foo[Int, List]) // solves ?M = [X[_]]Foo[Int, X[_]] ?A = List ...
7+
}
8+
9+
object Test2 {
10+
trait TC[T]
11+
class Foo[F[_], G[_]]
12+
def meh[GG[_[_]]](g: GG[TC]) = ???
13+
meh(new Foo[TC, TC]) // solves ?G = [X[_]]Foo[TC, X]
14+
}
15+
16+
object Test3 {
17+
trait TC[F[_]]
18+
trait TC2[F[_]]
19+
class Foo[F[_[_]], G[_[_]]]
20+
new Foo[TC, TC2]
21+
22+
def meh[G[_[_[_]]]](g: G[TC2]) = ???
23+
meh(new Foo[TC, TC2]) // solves ?G = [X[_[_]]]Foo[TC, X]
24+
}

0 commit comments

Comments
 (0)