diff --git a/include/element.h b/include/element.h index d5a48dc..754e7e9 100644 --- a/include/element.h +++ b/include/element.h @@ -43,14 +43,14 @@ struct ValType { virtual ~ValType() = default; }; -struct TemplateType : ValType { +struct TemplateType : ValType, std::enable_shared_from_this { ValType::Type type() const override; shared_ptr struct_replace(shared_ptr, map, shared_ptr>&) override; shared_ptr function_replace(const map, shared_ptr>&, map, shared_ptr>&) override; bool sameType(shared_ptr, set, shared_ptr>>&) override; }; -struct StructType : ValType { +struct StructType : ValType, std::enable_shared_from_this { ValType::Type type() const override; shared_ptr struct_replace(shared_ptr, map, shared_ptr>&) override; shared_ptr function_replace(const map, shared_ptr>&, map, shared_ptr>&) override; @@ -59,7 +59,7 @@ struct StructType : ValType { map, shared_ptr> mp; }; -struct FunctionType : ValType { +struct FunctionType : ValType, std::enable_shared_from_this { ValType::Type type() const override; shared_ptr struct_replace(shared_ptr, map, shared_ptr>&) override; shared_ptr function_replace(const map, shared_ptr>&, map, shared_ptr>&) override; diff --git a/scripts/check.py b/scripts/check.py index bbf5355..1e7f2fb 100644 --- a/scripts/check.py +++ b/scripts/check.py @@ -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} 应该编译失败,但是没有发现错误') diff --git a/src/element.cpp b/src/element.cpp index 2d8fc84..c0a67b1 100644 --- a/src/element.cpp +++ b/src/element.cpp @@ -16,7 +16,7 @@ ValType::Type FunctionType::type() const { } shared_ptr TemplateType::struct_replace(shared_ptr ut, map, shared_ptr> &eq) { - auto vt = shared_ptr(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 struct_replace(shared_ptr vt, shared_ptr TemplateType::function_replace(const map, shared_ptr> &mp, map, shared_ptr> &eq) { - auto tt = shared_ptr(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 function_replace(shared_ptr t, const map b, set, shared_ptr>> &eq) { - auto aa = shared_ptr(this), bb = static_pointer_cast(b); + auto aa = shared_from_this(), bb = static_pointer_cast(b); return aa == bb || eq.find({aa, bb}) != eq.end(); }