Create a where keyword
Can we have a where keyword for alternative limiting of parameters, results, and generics(if supported)
here are some examples..
Type Constraints
//Limit Parameter to Type
void example(BaseType a) where a is DerivedTypeA
{
}
//Limit Parameter to Type's
void example(BaseType a) where a is DerivedTypeA, DerivedTypeB
{
}
//Limit Result to Type
void example(BaseType a) where result is DerivedTypeA
{
}
//Limit Result to Type's
void example(BaseType a) where a is DerivedTypeA, DerivedTypeB
{
}
Variable Constraints
//Limit Parameter to Variable Type
void example(BaseType a, BaseType b, BaseType c) where a is b
{
}
//Limit Parameter to Variable Type's
void example(BaseType a, BaseType b, BaseType c) where a is b, c
{
}
//Limit Parameter to Expression
void example(BaseType a, BaseType b, BaseType c) where a is <some expression or method>
{
}
//Limit Result to Variable Type
BaseType example(BaseType a, BaseType b, BaseType c) where result is b
{
}
//Limit Result to Variable Type's
BaseType example(BaseType a, BaseType b, BaseType c) where result is b, c
{
}
//Limit Result to Expression
BaseType example(BaseType a, BaseType b, BaseType c) where result is <some expression or method>
{
}
Generics Constraints
//Limit Generic Parameter to Variable Type
void example<T>(T a, BaseType b, BaseType c) where T is b
{
}
//Limit Generic Parameter to Variable Type's
void example<T>(T a, BaseType b, BaseType c) where T is b, c
{
}
//Limit Generic Parameter to Expression
void example<T>(T a, BaseType b, BaseType c) where T is <some expression or method>
{
}
//Limit Generic Result to Variable Type
T example<T>(BaseType a, BaseType b, BaseType c) where T is b
{
}
//Limit Generic Result to Variable Type's
T example<T>(BaseType a, BaseType b, BaseType c) where T is b, c
{
}
//Limit Result to Expression
T example<T>(BaseType a, BaseType b, BaseType c) where T is <some expression or method>
{
}
Note this would allow generic restrictions without generics I think it would be a better and more clear implementation of requires and ensures.
EDIT: This would also be a step towards C# code compatibility if that is a thing vala wants to do.
Edited by Shadowblitz16