Skip to content

Allow by-name types in using clauses #12001

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1324,9 +1324,9 @@ object Parsers {
* | MatchType
* | InfixType
* FunType ::= (MonoFunType | PolyFunType)
* MonoFunType ::= FunArgTypes (‘=>’ | ‘?=>’) Type
* MonoFunType ::= FunTypeArgs (‘=>’ | ‘?=>’) Type
* PolyFunType ::= HKTypeParamClause '=>' Type
* FunArgTypes ::= InfixType
* FunTypeArgs ::= InfixType
* | `(' [ [ ‘[using]’ ‘['erased'] FunArgType {`,' FunArgType } ] `)'
* | '(' [ ‘[using]’ ‘['erased'] TypedFunParam {',' TypedFunParam } ')'
*/
Expand Down Expand Up @@ -1364,7 +1364,7 @@ object Parsers {
else
Function(params, t)
}
def funArgTypesRest(first: Tree, following: () => Tree) = {
def funTypeArgsRest(first: Tree, following: () => Tree) = {
val buf = new ListBuffer[Tree] += first
while (in.token == COMMA) {
in.nextToken()
Expand All @@ -1387,11 +1387,11 @@ object Parsers {
val ts = funArgType() match {
case Ident(name) if name != tpnme.WILDCARD && in.isColon() =>
isValParamList = true
funArgTypesRest(
funTypeArgsRest(
typedFunParam(paramStart, name.toTermName, imods),
() => typedFunParam(in.offset, ident(), imods))
case t =>
funArgTypesRest(t, funArgType)
funTypeArgsRest(t, funArgType)
}
accept(RPAREN)
if isValParamList || in.isArrow then
Expand Down Expand Up @@ -2907,10 +2907,10 @@ object Parsers {
def typeParamClauseOpt(ownerKind: ParamOwner.Value): List[TypeDef] =
if (in.token == LBRACKET) typeParamClause(ownerKind) else Nil

/** ContextTypes ::= Type {‘,’ Type}
/** ContextTypes ::= FunArgType {‘,’ FunArgType}
*/
def contextTypes(ofClass: Boolean, nparams: Int, impliedMods: Modifiers): List[ValDef] =
val tps = commaSeparated(typ)
val tps = commaSeparated(funArgType)
var counter = nparams
def nextIdx = { counter += 1; counter }
val paramFlags = if ofClass then Private | Local | ParamAccessor else Param
Expand Down
11 changes: 6 additions & 5 deletions docs/docs/internals/syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,10 @@ Type ::= FunType
| FunParamClause ‘=>>’ Type TermLambdaTypeTree(ps, t)
| MatchType
| InfixType
FunType ::= FunArgTypes (‘=>’ | ‘?=>’) Type Function(ts, t)
FunType ::= FunTypeArgs (‘=>’ | ‘?=>’) Type Function(ts, t)
| HKTypeParamClause '=>' Type PolyFunction(ps, t)
FunArgTypes ::= InfixType
| ‘(’ [ FunArgType {‘,’ FunArgType } ] ‘)’
FunTypeArgs ::= InfixType
| ‘(’ [ FunArgTypes ] ‘)’
| FunParamClause
FunParamClause ::= ‘(’ TypedFunParam {‘,’ TypedFunParam } ‘)’
TypedFunParam ::= id ‘:’ Type
Expand All @@ -191,6 +191,7 @@ Singleton ::= SimpleRef
Singletons ::= Singleton { ‘,’ Singleton }
FunArgType ::= Type
| ‘=>’ Type PrefixOp(=>, t)
FunArgTypes ::= FunArgType { ‘,’ FunArgType }
ParamType ::= [‘=>’] ParamValueType
ParamValueType ::= Type [‘*’] PostfixOp(t, "*")
TypeArgs ::= ‘[’ Types ‘]’ ts
Expand Down Expand Up @@ -323,15 +324,15 @@ HkTypeParam ::= {Annotation} [‘+’ | ‘-’] (id [HkTypeParamClause]

ClsParamClauses ::= {ClsParamClause} [[nl] ‘(’ [‘implicit’] ClsParams ‘)’]
ClsParamClause ::= [nl] ‘(’ ClsParams ‘)’
| [nl] ‘(’ ‘using’ (ClsParams | Types) ‘)’
| [nl] ‘(’ ‘using’ (ClsParams | FunArgTypes) ‘)’
ClsParams ::= ClsParam {‘,’ ClsParam}
ClsParam ::= {Annotation} ValDef(mods, id, tpe, expr) -- point of mods on val/var
[{Modifier} (‘val’ | ‘var’) | ‘inline’] Param
Param ::= id ‘:’ ParamType [‘=’ Expr]

DefParamClauses ::= {DefParamClause} [[nl] ‘(’ [‘implicit’] DefParams ‘)’]
DefParamClause ::= [nl] ‘(’ DefParams ‘)’ | UsingParamClause
UsingParamClause ::= [nl] ‘(’ ‘using’ (DefParams | Types) ‘)’
UsingParamClause ::= [nl] ‘(’ ‘using’ (DefParams | FunArgTypes) ‘)’
DefParams ::= DefParam {‘,’ DefParam}
DefParam ::= {Annotation} [‘inline’] Param ValDef(mods, id, tpe, expr) -- point of mods at id.
```
Expand Down
11 changes: 6 additions & 5 deletions docs/docs/reference/syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,10 @@ Type ::= FunType
| FunParamClause ‘=>>’ Type
| MatchType
| InfixType
FunType ::= FunArgTypes (‘=>’ | ‘?=>’) Type
FunType ::= FunTypeArgs (‘=>’ | ‘?=>’) Type
| HKTypeParamClause '=>' Type
FunArgTypes ::= InfixType
| ‘(’ [ FunArgType {‘,’ FunArgType } ] ‘)’
FunTypeArgs ::= InfixType
| ‘(’ [ FunArgTypes ] ‘)’
| FunParamClause
FunParamClause ::= ‘(’ TypedFunParam {‘,’ TypedFunParam } ‘)’
TypedFunParam ::= id ‘:’ Type
Expand All @@ -189,6 +189,7 @@ Singleton ::= SimpleRef

FunArgType ::= Type
| ‘=>’ Type
FunArgTypes ::= FunArgType { ‘,’ FunArgType }
ParamType ::= [‘=>’] ParamValueType
ParamValueType ::= Type [‘*’]
TypeArgs ::= ‘[’ Types ‘]’
Expand Down Expand Up @@ -311,14 +312,14 @@ HkTypeParam ::= {Annotation} [‘+’ | ‘-’] (id [HkTypeParamClause]

ClsParamClauses ::= {ClsParamClause} [[nl] ‘(’ [‘implicit’] ClsParams ‘)’]
ClsParamClause ::= [nl] ‘(’ ClsParams ‘)’
| [nl] ‘(’ ‘using’ (ClsParams | Types) ‘)’
| [nl] ‘(’ ‘using’ (ClsParams | FunArgTypes) ‘)’
ClsParams ::= ClsParam {‘,’ ClsParam}
ClsParam ::= {Annotation} [{Modifier} (‘val’ | ‘var’) | ‘inline’] Param
Param ::= id ‘:’ ParamType [‘=’ Expr]

DefParamClauses ::= {DefParamClause} [[nl] ‘(’ [‘implicit’] DefParams ‘)’]
DefParamClause ::= [nl] ‘(’ DefParams ‘)’ | UsingParamClause
UsingParamClause ::= [nl] ‘(’ ‘using’ (DefParams | Types) ‘)’
UsingParamClause ::= [nl] ‘(’ ‘using’ (DefParams | FunArgTypes) ‘)’
DefParams ::= DefParam {‘,’ DefParam}
DefParam ::= {Annotation} [‘inline’] Param
```
Expand Down
3 changes: 3 additions & 0 deletions tests/pos/i11997.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
def a(using i: => Int ) = () // ok
def b(using => Int ) = () // ok