Skip to content

Commit cf82715

Browse files
committed
Disallow curried type methods
Curried type methods open the possibility of partial applications. But this would give us full dependent typing, with types containing arbitrary terms (namely the arguments of the partial application).
1 parent ff14afa commit cf82715

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2200,7 +2200,7 @@ object Parsers {
22002200
Block(stats, Literal(Constant(())))
22012201
}
22022202

2203-
/** TypeDcl ::= id [TypTypeParamClause] {DefParamClause} TypeBounds ‘=’ TypeRHS
2203+
/** TypeDcl ::= id [TypTypeParamClause] [DefParamClause] TypeBounds ‘=’ TypeRHS
22042204
* | id [HkTypeParamClause] TypeBounds
22052205
*/
22062206
def typeDefOrDcl(start: Offset, mods: Modifiers): Tree = {
@@ -2209,6 +2209,7 @@ object Parsers {
22092209
val name = ident().toTypeName
22102210
val tparams = typeParamClauseOpt(ParamOwner.Type)
22112211
val vparamss = paramClauses(ParamOwner.Type)
2212+
if (vparamss.length > 1) syntaxError(i"type definitions cannot have multiple parameter clauses")
22122213
val isBounded = in.token == SUPERTYPE || in.token == SUBTYPE
22132214
val bounds = typeBounds()
22142215
val res =

docs/docs/internals/syntax.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ ValDcl ::= ids ‘:’ Type
313313
VarDcl ::= ids ‘:’ Type PatDef(_, ids, tpe, EmptyTree)
314314
DefDcl ::= DefSig [‘:’ Type] DefDef(_, name, tparams, vparamss, tpe, EmptyTree)
315315
DefSig ::= id [DefTypeParamClause] DefParamClauses
316-
TypeDcl ::= id [TypTypeParamClause] {DefParamClause} TypeBounds DefDef(name, tparams, vparamss, bounds, rhs)
316+
TypeDcl ::= id [TypTypeParamClause] [DefParamClause] TypeBounds DefDef(name, tparams, vparamss, bounds, rhs)
317317
‘=’ TypeRHS
318318
| id [HkTypeParamClause] TypeBounds TypeDef(name, tparams, bounds)
319319

tests/neg/typemethods.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,9 @@ object Test extends App {
1717
else S[ToNat(n - 1)]
1818

1919
type ToNat = Int // error: double definition
20+
21+
type Foo[T](n: Int)(m: Int) = Int // error: cannot be curried
22+
23+
type Bar(implicit m: Int) = Int // error: cannot be implicit
24+
type Baz(erased m: Int) = Int // error: cannot be erased
2025
}

0 commit comments

Comments
 (0)