This is the mail archive of the
kawa@sources.redhat.com
mailing list for the Kawa project.
Re: "cannot convert literal" warning
Dean Ferreyra wrote:
The warning, I think, is centered around the fact that the macro might
return the empty list. On the one hand, the warning could be saving us
from taking the CAR of the empty list. On the other hand, in the places
in our source where we do something like this, the arguments to the
macro are checked before hand so that the macro will never evaluate to
the empty list and the warnings do not help us.
It boils down to: is it desirable to get a warning for this?
(define (fn-pair1 flag)
(as <pair> (if flag '(1) '())))
I do think it is desirable to get a warning for:
(define (fn-pair2 flag)
(if flag (as <pair> '(1)) (as <pair> '())))
The two are of course equivalent. But one can argue that
the type of (if flag '(1) '()) is the union of <pair> and { '() }.
And asssuming we have "static type-checking" (such as I intend to
implement for XQuery, do we want:
(a) strict checking: a diagnostic if there *may* be a type
failure (not counting explicit casts) - i.e. if the expression
type is not a sub-set of the required type;
(b) loose checking: a diagnostic if there *will* be a type
failure (not counting explicit casts) - i.e. only if the
intersection between the expression type and the required type
is empty; or
(c) no compile-time type checking.
fn-pair1 causes a diagnotic with (a) but not (b);
fn-pair2 causes a disnostic with both (a) and (b).
I'd like options for all 3, but I suspect (b) is probably the
most appropriate default for Scheme (and XQuery).
Now that's the ideal. The code generator effectively rewrites
fn-pair1 to fn-pair2, and then attempts to do the cast at
compile-time. The cast fails, and we get the warning.
The right fix I think is for the code generator to do as
now, but if the cast fails just silently defer to cast to
run-time. Instead, the waning should be done at type-checking
time, which should be a separate pass *before* code-generation.
The "InlineCalls" pass does inlining *and* type propagation,
so that may be the right time to emit type warnings.
--
--Per Bothner
per@bothner.com http://per.bothner.com/