fix runtime error
This commit is contained in:
parent
3d1ffa838f
commit
7c43815968
@ -43,14 +43,14 @@ struct ValType {
|
||||
virtual ~ValType() = default;
|
||||
};
|
||||
|
||||
struct TemplateType : ValType {
|
||||
struct TemplateType : ValType, std::enable_shared_from_this<TemplateType> {
|
||||
ValType::Type type() const override;
|
||||
shared_ptr<ValType> struct_replace(shared_ptr<StructType>, map<shared_ptr<TemplateType>, shared_ptr<TemplateType>>&) override;
|
||||
shared_ptr<ValType> function_replace(const map<shared_ptr<TemplateType>, shared_ptr<ValType>>&, map<shared_ptr<TemplateType>, shared_ptr<TemplateType>>&) override;
|
||||
bool sameType(shared_ptr<ValType>, set<pair<shared_ptr<TemplateType>, shared_ptr<TemplateType>>>&) override;
|
||||
};
|
||||
|
||||
struct StructType : ValType {
|
||||
struct StructType : ValType, std::enable_shared_from_this<StructType> {
|
||||
ValType::Type type() const override;
|
||||
shared_ptr<ValType> struct_replace(shared_ptr<StructType>, map<shared_ptr<TemplateType>, shared_ptr<TemplateType>>&) override;
|
||||
shared_ptr<ValType> function_replace(const map<shared_ptr<TemplateType>, shared_ptr<ValType>>&, map<shared_ptr<TemplateType>, shared_ptr<TemplateType>>&) override;
|
||||
@ -59,7 +59,7 @@ struct StructType : ValType {
|
||||
map<shared_ptr<TemplateType>, shared_ptr<ValType>> mp;
|
||||
};
|
||||
|
||||
struct FunctionType : ValType {
|
||||
struct FunctionType : ValType, std::enable_shared_from_this<FunctionType> {
|
||||
ValType::Type type() const override;
|
||||
shared_ptr<ValType> struct_replace(shared_ptr<StructType>, map<shared_ptr<TemplateType>, shared_ptr<TemplateType>>&) override;
|
||||
shared_ptr<ValType> function_replace(const map<shared_ptr<TemplateType>, shared_ptr<ValType>>&, map<shared_ptr<TemplateType>, shared_ptr<TemplateType>>&) override;
|
||||
|
@ -23,6 +23,11 @@ def test_compiler(test_dir, should_fail):
|
||||
result = subprocess.run(['./acpa', file_path], capture_output=True, text=True)
|
||||
elapsed_time = time.time() - start_time
|
||||
|
||||
if result.returncode != 0:
|
||||
print(f' {Color.RED}测试失败:{Color.RESET} 在编译 {file_path} 时发生运行时错误')
|
||||
has_failed_tests = True
|
||||
continue
|
||||
|
||||
if should_fail:
|
||||
if 'error' not in result.stdout:
|
||||
print(f' {Color.RED}测试失败:{Color.RESET} {file_path} 应该编译失败,但是没有发现错误')
|
||||
|
@ -16,7 +16,7 @@ ValType::Type FunctionType::type() const {
|
||||
}
|
||||
|
||||
shared_ptr<ValType> TemplateType::struct_replace(shared_ptr<StructType> ut, map<shared_ptr<TemplateType>, shared_ptr<TemplateType>> &eq) {
|
||||
auto vt = shared_ptr<TemplateType>(this);
|
||||
auto vt = shared_from_this();
|
||||
auto it1 = ut->mp.find(vt);
|
||||
auto it2 = eq.find(vt);
|
||||
assert(it1 == ut->mp.end() || it2 == eq.end());
|
||||
@ -69,7 +69,7 @@ shared_ptr<ValType> struct_replace(shared_ptr<ValType> vt, shared_ptr<StructType
|
||||
}
|
||||
|
||||
shared_ptr<ValType> TemplateType::function_replace(const map<shared_ptr<TemplateType>, shared_ptr<ValType>> &mp, map<shared_ptr<TemplateType>, shared_ptr<TemplateType>> &eq) {
|
||||
auto tt = shared_ptr<TemplateType>(this);
|
||||
auto tt = shared_from_this();
|
||||
auto it1 = mp.find(tt);
|
||||
auto it2 = eq.find(tt);
|
||||
assert(it1 == mp.end() || it2 == eq.end());
|
||||
@ -112,7 +112,7 @@ shared_ptr<ValType> function_replace(shared_ptr<ValType> t, const map<shared_ptr
|
||||
}
|
||||
|
||||
bool TemplateType::sameType(shared_ptr<ValType> b, set<pair<shared_ptr<TemplateType>, shared_ptr<TemplateType>>> &eq) {
|
||||
auto aa = shared_ptr<TemplateType>(this), bb = static_pointer_cast<TemplateType>(b);
|
||||
auto aa = shared_from_this(), bb = static_pointer_cast<TemplateType>(b);
|
||||
return aa == bb || eq.find({aa, bb}) != eq.end();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user