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

ArkScript-lang / Ark / 14823373998

04 May 2025 05:03PM UTC coverage: 86.442% (+0.03%) from 86.409%
14823373998

push

github

SuperFola
fix: change the color of the function name inside runtime typechecking errors from blue to cyan to be easier to read inside dark terminals

0 of 1 new or added line in 1 file covered. (0.0%)

195 existing lines in 22 files now uncovered.

6835 of 7907 relevant lines covered (86.44%)

79668.53 hits per line

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

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

11
#ifndef INCLUDE_ARK_TYPECHECKER_HPP
12
#define INCLUDE_ARK_TYPECHECKER_HPP
13

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

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

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

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

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

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

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

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

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

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

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

105
    class ARK_API TypeCheckingError : public Error
69✔
106
    {
107
    public:
108
        TypeCheckingError(std::string&& funcname, const std::vector<Contract>& contracts, const std::vector<Value>& args) :
69✔
109
            Error("TypeCheckingError"),
69✔
110
            m_funcname(std::move(funcname)),
69✔
111
            m_contracts(contracts),
69✔
112
            m_passed_args(args)
69✔
113
        {}
207✔
114

115
        [[nodiscard]] std::string details(const bool colorize) const override
69✔
116
        {
69✔
117
            std::stringstream stream;
69✔
118
            generateError(m_funcname, m_contracts, m_passed_args, stream, colorize);
69✔
119
            return stream.str();
69✔
120
        }
69✔
121

122
    private:
123
        std::string m_funcname;
124
        std::vector<Contract> m_contracts;
125
        std::vector<Value> m_passed_args;
126
    };
127
}
128

129
#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