[erlang-questions] Wrong compilation warning
Kostis Sagonas
kostis@REDACTED
Thu Feb 7 00:23:36 CET 2008
Robert Virding wrote:
> On 06/02/2008, *Kostis Sagonas* <kostis@REDACTED
> <mailto:kostis@REDACTED>> wrote:
>
> Maxim Treskin wrote:
> >>...
> > -record(core_state, {
> > ctx_ids = [] :: [#ctx_ids{}],
> > contexts = [] :: [#context{}]
> > }).
> >
> > I see a warning:
> > Warning: record context is unused
> >
> > Record #context is unused in code, except in definition of record
> > #core_state. May be is it compilation bug?
>
> Well, a superfluous warning, even if bogus, is clearly not a compilation
> bug. In your code the culprit is the linter (erl_lint) that has not
> been adapted to take into account type annotations in record
> declarations.
> This might happen soon -- possibly even in the next R12 release.
>
>
> No, the warning is absolutely correct, the record context has not been
> used. All the type declaration says is that a record of type context
> *could* be used, but until you actually create a record of type context
> then it hasn't been used.
Sorry, I beg to differ. The warning is wrong.
First of all, the warning should read:
"the *declaration* of record context is unused".
If it actually meant what you suggested above, then the compiler should
also spit out a warning in the following code:
----------------------------------------
-record(context, ...).
is_context{X) -> is_record(X, context).
----------------------------------------
as this code does not really create any context record.
Anyway, my point is that the compiler should not warn when the
declaration of a record is needed for some reason. In Maxim's code, the
declaration of the context record is needed for the type declaration of
fields of some other record. Without it, the file does not compile.
The compiler cannot spit a warning for something that results in a
compilation error if you fix the way the warning suggests.
> I'm just waiting (NOT) for day we see a compiler error "missing type
> declaration". :-)
You'll never see such a compiler *error*, but the day you'll see such a
warning might be sooner than you think...
Cheers,
Kostis
PS. While playing with the compiler, I was somewhat surprised to
discover that there is no error/warning when a module does not
contain any export declaration. The compiler warns that all the
module's functions are unused but other than that the module happily
compiles & loads. I found that slightly weird...
More information about the erlang-questions
mailing list