public ITypeCheckType TypeCheck(ITypeEnvironment env)
{
Action<VarAccessEventArgs> onVarAccess = (args) => args.SetVarInstance(0);
//TODO: Make it so no casting is needed
((Environment.TypeEnvironment)env).VarAccess += onVarAccess;
if (!env.IsDeclared(Name))
{
env.ReportError(String.Format("Attempting to use 'sum' on a non-existing variable '{0}'." +
"'sum' can only be used on variables used in a repeat.",
Name), SourceStartPosition, SourceEndPosition);
return new UnknownType();
}
ITypeCheckType type = env.GetDeclared(Name);
if (!type.CompatibleWith(ExpressionUpperBound))
{
env.ReportError(String.Format("Sum not possible. Incompatible type: '{0}'. Only numeric types are supported.",
type), SourceStartPosition, SourceEndPosition);
return ExpressionUpperBound;
}
//TODO: Make it so no casting is needed
((Environment.TypeEnvironment)env).VarAccess -= onVarAccess;
return type;
}