Module Name: src
Committed By: rillig
Date: Mon Mar 22 15:29:43 UTC 2021
Modified Files:
src/tests/usr.bin/xlint/lint1: msg_171.c msg_171.exp
src/usr.bin/xlint/lint1: err.c tree.c
Log Message:
lint: use precise type information in message about type mismatch
While here, reword the message, avoiding operators and parentheses.
Since 2021-01-02, providing the precise type name is as easy as the
broad type classification (just replace tspec_name with type_name), and
it's definitely more useful to the human readers.
To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/msg_171.c
cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/xlint/lint1/msg_171.exp
cvs rdiff -u -r1.91 -r1.92 src/usr.bin/xlint/lint1/err.c
cvs rdiff -u -r1.245 -r1.246 src/usr.bin/xlint/lint1/tree.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/tests/usr.bin/xlint/lint1/msg_171.c
diff -u src/tests/usr.bin/xlint/lint1/msg_171.c:1.3 src/tests/usr.bin/xlint/lint1/msg_171.c:1.4
--- src/tests/usr.bin/xlint/lint1/msg_171.c:1.3 Mon Mar 22 15:05:00 2021
+++ src/tests/usr.bin/xlint/lint1/msg_171.c Mon Mar 22 15:29:43 2021
@@ -1,7 +1,7 @@
-/* $NetBSD: msg_171.c,v 1.3 2021/03/22 15:05:00 rillig Exp $ */
+/* $NetBSD: msg_171.c,v 1.4 2021/03/22 15:29:43 rillig Exp $ */
# 3 "msg_171.c"
-// Test for message: assignment type mismatch (%s != %s) [171]
+// Test for message: cannot assign to '%s' from '%s' [171]
struct s {
int member;
Index: src/tests/usr.bin/xlint/lint1/msg_171.exp
diff -u src/tests/usr.bin/xlint/lint1/msg_171.exp:1.4 src/tests/usr.bin/xlint/lint1/msg_171.exp:1.5
--- src/tests/usr.bin/xlint/lint1/msg_171.exp:1.4 Mon Mar 22 15:05:00 2021
+++ src/tests/usr.bin/xlint/lint1/msg_171.exp Mon Mar 22 15:29:43 2021
@@ -1,5 +1,5 @@
-msg_171.c(14): error: assignment type mismatch (int != struct) [171]
-msg_171.c(15): error: assignment type mismatch (struct != int) [171]
-msg_171.c(17): error: assignment type mismatch (pointer != struct) [171]
-msg_171.c(18): error: assignment type mismatch (struct != pointer) [171]
-msg_171.c(36): error: assignment type mismatch (struct != pointer) [171]
+msg_171.c(14): error: cannot assign to 'int' from 'struct s' [171]
+msg_171.c(15): error: cannot assign to 'struct s' from 'int' [171]
+msg_171.c(17): error: cannot assign to 'pointer to void' from 'struct s' [171]
+msg_171.c(18): error: cannot assign to 'struct s' from 'pointer to void' [171]
+msg_171.c(36): error: cannot assign to 'struct point' from 'pointer to struct point' [171]
Index: src/usr.bin/xlint/lint1/err.c
diff -u src/usr.bin/xlint/lint1/err.c:1.91 src/usr.bin/xlint/lint1/err.c:1.92
--- src/usr.bin/xlint/lint1/err.c:1.91 Sun Mar 21 20:44:59 2021
+++ src/usr.bin/xlint/lint1/err.c Mon Mar 22 15:29:43 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: err.c,v 1.91 2021/03/21 20:44:59 rillig Exp $ */
+/* $NetBSD: err.c,v 1.92 2021/03/22 15:29:43 rillig Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: err.c,v 1.91 2021/03/21 20:44:59 rillig Exp $");
+__RCSID("$NetBSD: err.c,v 1.92 2021/03/22 15:29:43 rillig Exp $");
#endif
#include <sys/types.h>
@@ -225,7 +225,7 @@ const char *msgs[] = {
"array subscript cannot be > %d: %ld", /* 168 */
"precedence confusion possible: parenthesize!", /* 169 */
"first operand must have scalar type, op ? :", /* 170 */
- "assignment type mismatch (%s != %s)", /* 171 */
+ "cannot assign to '%s' from '%s'", /* 171 */
"too many struct/union initializers", /* 172 */
"too many array initializers, expected %d", /* 173 */
"too many initializers", /* 174 */
Index: src/usr.bin/xlint/lint1/tree.c
diff -u src/usr.bin/xlint/lint1/tree.c:1.245 src/usr.bin/xlint/lint1/tree.c:1.246
--- src/usr.bin/xlint/lint1/tree.c:1.245 Sun Mar 21 19:08:10 2021
+++ src/usr.bin/xlint/lint1/tree.c Mon Mar 22 15:29:43 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: tree.c,v 1.245 2021/03/21 19:08:10 rillig Exp $ */
+/* $NetBSD: tree.c,v 1.246 2021/03/22 15:29:43 rillig Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: tree.c,v 1.245 2021/03/21 19:08:10 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.246 2021/03/22 15:29:43 rillig Exp $");
#endif
#include <float.h>
@@ -63,7 +63,8 @@ static void check_enum_int_mismatch(op_t
const tnode_t *, const tnode_t *);
static tnode_t *new_tnode(op_t, type_t *, tnode_t *, tnode_t *);
static void balance(op_t, tnode_t **, tnode_t **);
-static void warn_incompatible_types(op_t, tspec_t, tspec_t);
+static void warn_incompatible_types(op_t, const type_t *, tspec_t,
+ const type_t *, tspec_t);
static void warn_incompatible_pointers(const mod_t *,
const type_t *, const type_t *);
static void merge_qualifiers(type_t **, type_t *, type_t *);
@@ -845,11 +846,13 @@ typeok_star(tspec_t t)
}
static bool
-typeok_plus(op_t op, tspec_t lt, tspec_t rt)
+typeok_plus(op_t op,
+ const type_t *ltp, tspec_t lt,
+ const type_t *rtp, tspec_t rt)
{
/* operands have scalar types (checked above) */
if ((lt == PTR && !is_integer(rt)) || (rt == PTR && !is_integer(lt))) {
- warn_incompatible_types(op, lt, rt);
+ warn_incompatible_types(op, ltp, lt, rtp, rt);
return false;
}
return true;
@@ -862,10 +865,10 @@ typeok_minus(op_t op,
{
/* operands have scalar types (checked above) */
if (lt == PTR && (!is_integer(rt) && rt != PTR)) {
- warn_incompatible_types(op, lt, rt);
+ warn_incompatible_types(op, ltp, lt, rtp, rt);
return false;
} else if (rt == PTR && lt != PTR) {
- warn_incompatible_types(op, lt, rt);
+ warn_incompatible_types(op, ltp, lt, rtp, rt);
return false;
}
if (lt == PTR && rt == PTR) {
@@ -990,7 +993,7 @@ typeok_ordered_comparison(op_t op,
return true;
if (!is_integer(lt) && !is_integer(rt)) {
- warn_incompatible_types(op, lt, rt);
+ warn_incompatible_types(op, ltp, lt, rtp, rt);
return false;
}
@@ -1264,30 +1267,32 @@ typeok_scalar_strict_bool(op_t op, const
/* Check the types using the information from modtab[]. */
static bool
-typeok_scalar(op_t op, const mod_t *mp, tspec_t lt, tspec_t rt)
+typeok_scalar(op_t op, const mod_t *mp,
+ const type_t *ltp, tspec_t lt,
+ const type_t *rtp, tspec_t rt)
{
if (mp->m_takes_bool && lt == BOOL && rt == BOOL)
return true;
if (mp->m_requires_integer) {
if (!is_integer(lt) || (mp->m_binary && !is_integer(rt))) {
- warn_incompatible_types(op, lt, rt);
+ warn_incompatible_types(op, ltp, lt, rtp, rt);
return false;
}
} else if (mp->m_requires_integer_or_complex) {
if ((!is_integer(lt) && !is_complex(lt)) ||
(mp->m_binary && (!is_integer(rt) && !is_complex(rt)))) {
- warn_incompatible_types(op, lt, rt);
+ warn_incompatible_types(op, ltp, lt, rtp, rt);
return false;
}
} else if (mp->m_requires_scalar) {
if (!is_scalar(lt) || (mp->m_binary && !is_scalar(rt))) {
- warn_incompatible_types(op, lt, rt);
+ warn_incompatible_types(op, ltp, lt, rtp, rt);
return false;
}
} else if (mp->m_requires_arith) {
if (!is_arithmetic(lt) ||
(mp->m_binary && !is_arithmetic(rt))) {
- warn_incompatible_types(op, lt, rt);
+ warn_incompatible_types(op, ltp, lt, rtp, rt);
return false;
}
}
@@ -1342,7 +1347,7 @@ typeok_op(op_t op, const mod_t *mp, int
return false;
break;
case PLUS:
- if (!typeok_plus(op, lt, rt))
+ if (!typeok_plus(op, ltp, lt, rtp, rt))
return false;
break;
case MINUS:
@@ -1396,7 +1401,7 @@ typeok_op(op_t op, const mod_t *mp, int
case SUBASS:
/* operands have scalar types (checked above) */
if ((lt == PTR && !is_integer(rt)) || rt == PTR) {
- warn_incompatible_types(op, lt, rt);
+ warn_incompatible_types(op, ltp, lt, rtp, rt);
return false;
}
goto assign;
@@ -1493,7 +1498,7 @@ typeok(op_t op, int arg, const tnode_t *
if (Tflag && !typeok_scalar_strict_bool(op, mp, arg, ln, rn))
return false;
- if (!typeok_scalar(op, mp, lt, rt))
+ if (!typeok_scalar(op, mp, ltp, lt, rtp, rt))
return false;
if (!typeok_op(op, mp, arg, ln, ltp, lt, rn, rtp, rt))
@@ -1677,7 +1682,7 @@ check_assign_types_compatible(op_t op, i
warning(155, arg);
break;
default:
- warn_incompatible_types(op, lt, rt);
+ warn_incompatible_types(op, ltp, lt, rtp, rt);
break;
}
@@ -2528,7 +2533,9 @@ convert_constant(op_t op, int arg, type_
* Prints a appropriate warning.
*/
static void
-warn_incompatible_types(op_t op, tspec_t lt, tspec_t rt)
+warn_incompatible_types(op_t op,
+ const type_t *ltp, tspec_t lt,
+ const type_t *rtp, tspec_t rt)
{
const mod_t *mp;
@@ -2543,8 +2550,8 @@ warn_incompatible_types(op_t op, tspec_t
/* assignment of different structures (%s != %s) */
error(240, tspec_name(lt), tspec_name(rt));
} else {
- /* assignment type mismatch (%s != %s) */
- error(171, tspec_name(lt), tspec_name(rt));
+ /* cannot assign to '%s' from '%s' */
+ error(171, type_name(ltp), type_name(rtp));
}
} else if (mp->m_binary) {
/* operands of '%s' have incompatible types (%s != %s) */