This spec assumes the existance of implicit funtion types.
LocalModifier ::= ‘unused’
FunMods ::= ‘unused’
| ImplicitFunMods
ImplicitFunMods ::= ‘implcit’ [‘unused’]
| ‘unused’ ‘implcit’
ClsParamClauses ::= {ClsParamClause} [[nl] `(' [ImplicitFunMods] ClsParams `)']
ClsParamClause ::= [nl] `(' [[`unused'] ClsParams] ')'
ParamClauses ::= {ParamClause} [nl] ‘(’ [[ImplicitFunMods] Params] ‘)’
ParamClause ::= [nl] ‘(’ [‘unused’] Params ‘)’
Type ::= [FunMods] FunArgTypes `=>' Type
| HkTypeParamClause `->' Type
| InfixType
Expr ::= [FunArgMods] FunParams =>' Expr
| Expr1
Template members, parameters, methods and values labeled with an unused modifier can only be passed to unused parameters. The implicit modifier is illegal for all type members, variable, lazy values, classes, traits and objects.
An implicit parameter list (unused p1,...,pn) of a method marks the parameters p1,...,pn as unused.
(unused p1,...,pn) unused def
and unused val
define unused values, non of which will be present at runtime.
A method with unused parameters can be applied to arguments just like a normal method. In this case the unused label has no effect on the argument. However, the result of the evaluation of the argument will not be passed to the function. If the argument is itself marked as unused it will not be evaluated.
Conversly, if method without unused parameters is applied to unused arguments, the compiler will issue an error signaling the atempt of usuing the unused
value.
Note that unused
values can only be passed to a method with unused parameters. Unused values can also be present in statement position
A type unused (T1,...Tn) => R
is a function type for which all its parameters are unused.
Likewise a closure unused (x1,...,xn) => ...
is a closure for which all its parameters are marked as unused.
These function types are not compatible with normal function types and must have at least one parameter.
Like unused closures, unused method types and normal method types are incompatible. This forces overrides to have the same unused parameters.
Overload resolution, implcit resolution and type inference (typer) should not be affected by the presence of unused parameters and values. Static errors should be emitted after the normal resolution takes place. The only exeption to this previous rule is the addition of the unused funtion types.
unused val z: R = ...
def foo(unused x: X)(y: T): R = {
bar(x)(y) // Error: `x` is not unused in `bar`
baz(x)(y) // Error: `baz` is unused and can not be returned
}
def bar(x: X)(unused y: Y): R = {
bar(x)(y) // Error: y is not unused in foo
a // Error: `z` is unused and can not be returned
}
unused def baz(x: X)(unused y: Y): R = {
// in here we can do anything with unused values because `baz` will never be used
???
}
Hey! 🙂
Is this the latest spec?
I was just wondering, what might happen, if I try to assign an unused value.
Edit: I tried the current version, and it seems, the implementation is in line with my intuition. 😄