gpc 20070904, based on gcc-3.4.5 (mingw special)
I got a compilation error, "expression used as a statement". When I finally realized I had a unit and a procedure in the unit with the same name, I changed one name and the error went away, so I'm guessing the duplication of name was somehow responsible.
I am not asking to be allowed to name a unit the same as some entity within the unit. I am asking that the error message be changed to something that would have spared me thrashing around until I noticed that I had duplicated a name.
Failing that, could someone explain how what I did was an "expression used as a statement"?
gpc -c -x Pascal jsm2m.int gpc -c jsm2.pas
jsm2.pas: In main program: jsm2.pas:5: error: expression used as a statement
Jay Michael wrote:
gpc 20070904, based on gcc-3.4.5 (mingw special)
I got a compilation error, "expression used as a statement". When
I finally realized I had a unit and a procedure in the unit with the same name, I changed one name and the error went away, so I'm guessing the duplication of name was somehow responsible.
I am not asking to be allowed to name a unit the same as some
entity within the unit.
Actually currently you can (you probably should get an error earlier). Just write:
jsm2m.jsm2m;
I am asking that the error message be changed to something that would have spared me thrashing around until I noticed that I had duplicated a name.
Failing that, could someone explain how what I did was an
"expression used as a statement"?
I can explain how compiler produced this message. Parsing the
jsm2m;
line compiler realised that this must be a procedure call, so it attempted to call 'jsm2m'. But it found that 'jsm2m' names interface, not a procedure. More precisely, compiler was unable to find procedure or equivalent (gpc allows some things which strictly speaking are not procedures to be called like procedures) of name 'jsm2m', but 'jsm2m' looked as something sensible (attempt at compiling it did not produce an error). Given this compiler decided to emit this message.
I agree that error message is confusing. OTOH what compiler should do. One could argue that compiler should emit error message at your 'uses' statement. However, 'uses' is an UCSD Pascal constuct, which we tried to keep compatible with Turbo Pascal. And Turbo Pascal tends to ignore name clashes due to imports. If you use Extended Pascal 'import' statement then you do get error during import and that is clearer:
jsm2.pas:2: error: bad import jsm2m.pas:3: error: redeclaration of `Jsm2m' jsm2.pas:2: error: previous declaration
For the compiler 'jsm2m' is an expression which produces a value: corresponding interface. It behaves as a somewhat restricted record: you can use dot notation to extract components (exports of the interface).
In your case message like below would be more appropriate:
error: attempting to call interface
However, there is a lot of things which may appear at this place, so trying to describe the object that compiler has requires some effort. OTOH, if there are no name clashes then usually it is clear why the object can not be called.
Also, compiler has more or less the same information when you write:
2 + 2;
or
a = b + c;
Note that the third one was probably intended to be assignment statement, but in Pascal '=' tests for equality. In both cases the user probably tried to write a statement, but for some reason it is incomplete. Some people expect that in such cases compiler should ignore the value, and the message makes clear that this is illegal in Pascal (one needs to do something with the value to get a statement).
To put it differently, there are two typical scenarios which from compiler point of view look the same:
1) user attempts to call something which is not a routine. 2) user wanted to write a statement, but it is somewhat incomplete and we only have part of it (that is an expression).