public TypeSpec Verify() { var baseType = VarTab.Get(Id); if (baseType.ArrayCount < ArrayIndex.Count) { throw new ArgumentException(); } return(new TypeSpec { ArrayCount = baseType.ArrayCount - ArrayIndex.Count, Base = baseType.Base }); }
public TypeSpec Verify() { var baseType = VarTab.Get(Id); if (baseType.ArrayCount > 0 || !(baseType.Base is Function func)) { throw new ArgumentException(); } var argIds = Args.Select(x => x.Id).ToHashSet(); var parIds = func.Types.Select(x => x.Id).ToHashSet(); if (!parIds.IsSupersetOf(argIds)) { throw new ArgumentException(); } if (!func.Types.Where(par => par.Default != null).Select(par => par.Id).ToHashSet() .IsSupersetOf(parIds.Except(argIds))) { throw new ArgumentException(); } (from arg in Args join par in func.Types on arg.Id equals par.Id select(arg, par)).ForEach(tup => { var(arg, par) = tup; if (arg.Expr.Verify() != par.Type) { throw new ArgumentException(); } }); return(func.ReturnType); }