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

ArkScript-lang / Ark / 14647441324

24 Apr 2025 05:07PM UTC coverage: 83.165% (+2.7%) from 80.417%
14647441324

push

github

SuperFola
feat(vm): compressing identical traces when displaying the stacktrace of an error

21 of 21 new or added lines in 1 file covered. (100.0%)

270 existing lines in 10 files now uncovered.

6580 of 7912 relevant lines covered (83.16%)

79046.5 hits per line

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

88.89
/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-2025
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
#include <sstream>
19

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

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

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

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

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

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

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

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

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

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

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

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

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

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