validation
[m6w6/ext-psi] / src / types / decl_arg.c
index bec8ddc..61aacef 100644 (file)
@@ -95,11 +95,13 @@ void psi_decl_arg_dump(int fd, struct psi_decl_arg *arg, unsigned level)
 bool psi_decl_arg_validate(struct psi_data *data, struct psi_decl_arg *arg,
                struct psi_validate_stack *type_stack)
 {
-       if (!psi_decl_type_validate(data, arg->type, type_stack)) {
-               data->error(data, arg->type->token, PSI_WARNING,
-                               "Cannot use '%s' as type for '%s': %s", arg->type->name,
-                               arg->var->name, data->last_error);
-               return false;
+       if (!psi_decl_type_validate(data, arg->type, arg->var->pointer_level, type_stack)) {
+                if (!arg->var->pointer_level) {
+                       data->error(data, arg->type->token, PSI_WARNING,
+                                       "Cannot use '%s' as type for '%s'%s%s", arg->type->name,
+                                       arg->var->name, *data->last_error ? ": " : "", data->last_error);
+                       return false;
+                }
        }
        return true;
 }
@@ -120,29 +122,27 @@ bool psi_decl_arg_validate_typedef(struct psi_data *data,
                                        "Type '%s' cannot be aliased to 'void'", def->type->name);
                        return false;
                }
-       } else if (!def->var->pointer_level) {
-               if (!psi_decl_type_validate(data, def->type, type_stack)) {
-                       const char *pre;
-
-                       switch (def->type->type) {
-                       case PSI_T_STRUCT:
-                               pre = "struct ";
-                               break;
-                       case PSI_T_UNION:
-                               pre = "union ";
-                               break;
-                       case PSI_T_ENUM:
-                               pre = "enum ";
-                               break;
-                       default:
-                               pre = "";
-                               break;
-                       }
-                       data->error(data, def->token, PSI_WARNING,
-                                       "Type '%s' cannot be aliased to '%s%s': %s", def->var->name, pre,
-                                       def->type->name, data->last_error);
-                       return false;
+       } else if (!psi_decl_type_validate(data, def->type, def->var->pointer_level, type_stack)) {
+               const char *pre;
+
+               switch (def->type->type) {
+               case PSI_T_STRUCT:
+                       pre = "struct ";
+                       break;
+               case PSI_T_UNION:
+                       pre = "union ";
+                       break;
+               case PSI_T_ENUM:
+                       pre = "enum ";
+                       break;
+               default:
+                       pre = "";
+                       break;
                }
+               data->error(data, def->token, PSI_WARNING,
+                               "Type '%s' cannot be aliased to '%s%s'%s%s", def->var->name, pre,
+                               def->type->name, *data->last_error ? ": " : "", data->last_error);
+               return false;
        }
 
        return true;