Has this ever happened to you?
(defined but not queried)
Useless stuff here
(program entry point)
(if) (queried but not defined) (then)
Huh??
(else)
Good!
(endif)
Warning: No library (such as stdlib.dg) was specified on the commandline.
Warning: queried_not_defined_warning.dg, line 1: Possible typo: A rule is defined for ‘(defined but not queried)’, but this predicate is never queried and has no interface definition.
Warning: Possible typo: A query is made to ‘(queried but not defined)’, but there is no matching rule or interface definition.
We get a line number for the (defined but not queried) warning, but no line number for the (queried but not defined) warning.
Why is that? This block seems like it should be reporting line numbers…
defined = (pred->flags & (PREDF_DEFINED | PREDF_DYNAMIC | PREDF_MACRO));
queried = pred->flags & PREDF_MENTIONED_IN_QUERY;
interface = !!pred->iface_decl;
if((pred->flags & PREDF_DEFINED) && !queried && !interface) {
assert(pred->nclause);
report(
LVL_WARN,
pred->clauses[0]->line,
"Possible typo: A rule is defined "
"for '%s', but this "
"predicate is never queried "
"and has no interface "
"definition.",
predname->printed_name);
} else if((pred->flags & PREDF_DYNAMIC) && !queried) {
report(
LVL_WARN,
0,
"Possible typo: '%s' appears in a "
"now-expression, but is "
"never queried.",
predname->printed_name);
} else if(queried && !defined && !interface) {
report(
LVL_WARN,
pred->invoked_at_line,
"Possible typo: A query is made to "
"'%s', but there is "
"no matching rule or "
"interface definition.",
predname->printed_name);
} else if(interface && !queried && !defined) {
report(
LVL_WARN,
pred->iface_decl->line,
"Possible typo: An interface is "
"defined for '%s', but there "
"is no matching rule "
"definition or query.",
predname->printed_name);
}
…but it turns out pred->invoked_at_line is only set when invocations are traced, which is after this block happens. Oops.
I made it so pred->invoked_at_line is set at the same place PREDF_MENTIONED_IN_QUERY is, so now we get:
Warning: No library (such as stdlib.dg) was specified on the commandline.
Warning: queried_not_defined_warning.dg, line 1: Possible typo: A rule is defined for ‘(defined but not queried)’, but this predicate is never queried and has no interface definition.
Warning: queried_not_defined_warning.dg, line 5: Possible typo: A query is made to ‘(queried but not defined)’, but there is no matching rule or interface definition.
Much better! I thought this was going to be a new feature, but it turned out to be an old (as in predating 1a/01) bug instead. This is going to make debugging typos a lot easier for me!
Pull request, as usual; I’m going to merge this one in a day or two unless someone strongly objects. It seems like a very clear bugfix to me.