~mil/mepo

86490d9a2c07021daf6158722de8246e373fe77e — Miles Alan 2 years ago 64ad185 mepolang_errorhandling
Add validation logic for validate_args to report type mismatch on fns
1 files changed, 16 insertions(+), 2 deletions(-)

M src/util/utilarg.zig
M src/util/utilarg.zig => src/util/utilarg.zig +16 -2
@@ 2,7 2,21 @@ const std = @import("std");
const types = @import("../types.zig");

pub fn validate_args(spec: types.MepoFnSpec, args: [types.MepoFnNargs]types.MepoArg) !bool {
    _ = args;
    _ = spec;
    for (spec.args) |expect_spec_arg, expect_spec_arg_i| {
        switch (expect_spec_arg) {
            .Number => {
                switch (args[expect_spec_arg_i]) {
                    .Text => return error.ExpectNumberGotText,
                    .Number => continue,
                }
            },
            .Text => {
                switch (args[expect_spec_arg_i]) {
                    .Number => return error.ExpectTextGotNumber,
                    .Text => continue,
                }
            },
        }
    }
    return true;
}