• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ArkScript-lang / Ark / 14316379818

07 Apr 2025 06:10PM UTC coverage: 80.073% (+0.7%) from 79.378%
14316379818

push

github

SuperFola
feat(tests, type checker): adding tests for the type checker error message generation (in isolation)

36 of 68 new or added lines in 2 files covered. (52.94%)

12 existing lines in 3 files now uncovered.

6128 of 7653 relevant lines covered (80.07%)

77599.75 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

82.61
/include/Ark/TypeChecker.hpp
1
/**
2
 * @file TypeChecker.hpp
3
 * @author Alexandre Plateau (lexplt.dev@gmail.com)
4
 * @brief
5
 * @version 1.1
6
 * @date 2022-01-16
7
 *
8
 * @copyright Copyright (c) 2022-2024
9
 *
10
 */
11

12
#ifndef INCLUDE_ARK_TYPECHECKER_HPP
13
#define INCLUDE_ARK_TYPECHECKER_HPP
14

15
#include <string>
16
#include <vector>
17
#include <ostream>
18

19
#include <Ark/VM/Value.hpp>
20

21
namespace Ark::types
22
{
23
    namespace details
24
    {
25
        template <typename T, typename... Ts>
26
        using AllSame = std::enable_if_t<std::conjunction_v<std::is_same<T, Ts>...>>;
27

28
        template <int I>
29
        [[nodiscard]] bool checkN(const std::vector<Value>& args)
10,120✔
30
        {
10,120✔
31
            return I >= args.size();
10,120✔
32
        }
33

34
        template <int I, typename T, typename... Ts>
35
        [[nodiscard]] bool checkN(const std::vector<Value>& args, T type, Ts... xs)
10,617✔
36
        {
10,617✔
37
            if (I >= args.size() || (type != ValueType::Any && args[I].valueType() != type))
10,617✔
38
                return false;
×
39
            return checkN<I + 1>(args, xs...);
10,617✔
40
        }
10,617✔
41
    }
42

43
    /**
44
     * @brief Helper to see if a builtin has been given a wanted set of types
45
     *
46
     * @tparam Ts Variadic argument list composed of ValueTypes
47
     * @param args arguments passed to the function
48
     * @param types accepted types
49
     * @return true if the contract is respected
50
     * @return false otherwise
51
     */
52
    template <typename... Ts, typename = details::AllSame<ValueType, Ts...>>
53
    [[nodiscard]] bool check(const std::vector<Value>& args, Ts... types)
10,274✔
54
    {
10,274✔
55
        if (sizeof...(types) != args.size())
10,274✔
56
            return false;
154✔
57
        return details::checkN<0>(args, types...);
10,120✔
58
    }
10,274✔
59

60
    /**
61
     * @brief A type definition within a contract
62
     *
63
     */
64
    struct ARK_API Typedef
87✔
65
    {
66
        std::string name;
67
        std::vector<ValueType> types;
68
        bool variadic;
69

70
        Typedef(const std::string& type_name, const ValueType type, const bool is_variadic = false) :
5✔
71
            name(type_name), types { type }, variadic(is_variadic)
5✔
72
        {}
10✔
73

NEW
74
        Typedef(const std::string& type_name, const std::vector<ValueType>& type_list, const bool is_variadic = false) :
×
75
            name(type_name), types(type_list), variadic(is_variadic)
×
76
        {}
×
77
    };
78

79
    /**
80
     * @brief A contract is a list of typed arguments that a function can follow
81
     *
82
     */
83
    struct ARK_API Contract
72✔
84
    {
85
        std::vector<Typedef> arguments;
86
    };
87

88
    /**
89
     * @brief Generate an error message based on a given set of types contracts provided argument list
90
     *
91
     * @param funcname ArkScript name of the function
92
     * @param contracts types contracts the function can follow
93
     * @param args provided argument list
94
     * @param os output stream, default to cout
95
     * @param colorize enable output colorizing
96
     */
97
    ARK_API void generateError [[noreturn]] (
98
        const std::string_view& funcname,
99
        const std::vector<Contract>& contracts,
100
        const std::vector<Value>& args,
101
        std::ostream& os = std::cout,
102
        bool colorize = true);
103
}
104

105
#endif
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc