Skip to content

Commit

Permalink
fix missed typecheck for TypeExpr
Browse files Browse the repository at this point in the history
  • Loading branch information
chloro-pn committed Jun 23, 2024
1 parent 722cdd1 commit 693ba6b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion include/wamon/type_checker.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class TypeChecker {
// 注意:全局变量和局部变量的类型合法性检测不在这个阶段进行,因为在语句合法性检测的时候所有函数结构体方法和全局变量都被解析,因此可以在语句合法性检测中检测
void CheckTypes();

void CheckType(const std::unique_ptr<Type>& type, const std::string& context_info, bool can_be_void = false);
void CheckType(const std::unique_ptr<Type>& type, const std::string& context_info, bool can_be_void = false) const;

// 检测全局变量的定义语句是否合法,全局变量的定义在包内是顺序相关的。
// 这应该是类型检测的第二个阶段(因为表达式合法性检测依赖名字查找,需要全局作用域的名字获得类型)
Expand Down
4 changes: 3 additions & 1 deletion src/type_checker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ void TypeChecker::CheckTypes() {
}
}

void TypeChecker::CheckType(const std::unique_ptr<Type>& type, const std::string& context_info, bool can_be_void) {
void TypeChecker::CheckType(const std::unique_ptr<Type>& type, const std::string& context_info,
bool can_be_void) const {
if (IsFuncType(type)) {
auto func_type = static_cast<FuncType*>(type.get());
for (auto& param : func_type->param_type_) {
Expand Down Expand Up @@ -708,6 +709,7 @@ std::unique_ptr<Type> TypeChecker::GetExpressionType(Expression* expr) const {
return CheckParamTypeAndGetResultTypeForMethod(*this, tmp);
}
if (auto tmp = dynamic_cast<TypeExpr*>(expr)) {
CheckType(tmp->GetType(), "check TypeExpr");
return tmp->GetType()->Clone();
}
if (auto tmp = dynamic_cast<LambdaExpr*>(expr)) {
Expand Down

0 comments on commit 693ba6b

Please sign in to comment.