瀏覽代碼

Fix using pointers bug with addressing struct fields

gingerBill 5 年之前
父節點
當前提交
2a684830f9
共有 1 個文件被更改,包括 2 次插入1 次删除
  1. 2 1
      src/check_stmt.cpp

+ 2 - 1
src/check_stmt.cpp

@@ -562,6 +562,7 @@ bool check_using_stmt_entity(CheckerContext *ctx, AstUsingStmt *us, Ast *expr, b
 	}
 	}
 
 
 	case Entity_Variable: {
 	case Entity_Variable: {
+		bool is_ptr = is_type_pointer(e->type);
 		Type *t = base_type(type_deref(e->type));
 		Type *t = base_type(type_deref(e->type));
 		if (t->kind == Type_Struct) {
 		if (t->kind == Type_Struct) {
 			// TODO(bill): Make it work for unions too
 			// TODO(bill): Make it work for unions too
@@ -570,7 +571,7 @@ bool check_using_stmt_entity(CheckerContext *ctx, AstUsingStmt *us, Ast *expr, b
 				Entity *f = found->elements.entries[i].value;
 				Entity *f = found->elements.entries[i].value;
 				if (f->kind == Entity_Variable) {
 				if (f->kind == Entity_Variable) {
 					Entity *uvar = alloc_entity_using_variable(e, f->token, f->type, expr);
 					Entity *uvar = alloc_entity_using_variable(e, f->token, f->type, expr);
-					if (e->flags & EntityFlag_Value) uvar->flags |= EntityFlag_Value;
+					if (!is_ptr && e->flags & EntityFlag_Value) uvar->flags |= EntityFlag_Value;
 					if (e->flags & EntityFlag_Param) uvar->flags |= EntityFlag_Param;
 					if (e->flags & EntityFlag_Param) uvar->flags |= EntityFlag_Param;
 					Entity *prev = scope_insert(ctx->scope, uvar);
 					Entity *prev = scope_insert(ctx->scope, uvar);
 					if (prev != nullptr) {
 					if (prev != nullptr) {