Browse Source

don't suggest u8 slice cast to string for u8 slice literal

JasperGeer 2 years ago
parent
commit
1a0930f841
1 changed files with 2 additions and 2 deletions
  1. 2 2
      src/check_expr.cpp

+ 2 - 2
src/check_expr.cpp

@@ -1998,7 +1998,7 @@ void check_assignment_error_suggestion(CheckerContext *c, Operand *o, Type *type
 		error_line("\tSuggestion: a string may be transmuted to %s\n", b);
 		error_line("\tSuggestion: a string may be transmuted to %s\n", b);
 		error_line("\t            This is an UNSAFE operation as string data is assumed to be immutable, \n");
 		error_line("\t            This is an UNSAFE operation as string data is assumed to be immutable, \n");
 		error_line("\t            whereas slices in general are assumed to be mutable.\n");
 		error_line("\t            whereas slices in general are assumed to be mutable.\n");
-	} else if (is_type_u8_slice(src) && are_types_identical(dst, t_string)) {
+	} else if (is_type_u8_slice(src) && are_types_identical(dst, t_string) && o->expr->kind != Ast_CompoundLit) {
 		error_line("\tSuggestion: the expression may be casted to %s\n", b);
 		error_line("\tSuggestion: the expression may be casted to %s\n", b);
 	}
 	}
 }
 }
@@ -2039,7 +2039,7 @@ void check_cast_error_suggestion(CheckerContext *c, Operand *o, Type *type) {
 		}
 		}
 	} else if (are_types_identical(src, t_string) && is_type_u8_slice(dst)) {
 	} else if (are_types_identical(src, t_string) && is_type_u8_slice(dst)) {
 		error_line("\tSuggestion: a string may be transmuted to %s\n", b);
 		error_line("\tSuggestion: a string may be transmuted to %s\n", b);
-	} else if (is_type_u8_slice(src) && are_types_identical(dst, t_string)) {
+	} else if (is_type_u8_slice(src) && are_types_identical(dst, t_string) && o->expr->kind != Ast_CompoundLit) {
 		error_line("\tSuggestion: the expression may be casted to %s\n", b);
 		error_line("\tSuggestion: the expression may be casted to %s\n", b);
 	}
 	}
 }
 }