Recent

Author Topic: Somewhat unusual error message  (Read 1313 times)

440bx

  • Hero Member
  • *****
  • Posts: 1988
Somewhat unusual error message
« on: February 05, 2020, 06:44:19 pm »
Hello,

This is just FYI since it really isn't a bug but, the result could be improved.  Consider the following code:
Code: Pascal  [Select][+][-]
  1. program TestParameterErrorMessage;
  2. const
  3.   B = 0;
  4.  
  5. type
  6.   R1 = array[0..10] of integer;
  7.  
  8.   R2 = record
  9.     a, b : integer;
  10.     c    : boolean
  11.   end;
  12.  
  13. var
  14.   x, y : integer;
  15.   z    : boolean;
  16.  
  17. procedure Q(var x : R1; z : R2);
  18. begin
  19. end;
  20.  
  21. begin
  22.   Q(x, B);
  23. end.
Parameters "x" and "B" are the wrong type and the compiler points it out as it should.

The compiler outputs the following error messages:
Quote
Compile Project, Mode: Default, Target: lib\i386-win32\ParameterTypeErrorMessage.exe: Exit code 1, Errors: 1, Hints: 3
ParameterTypeErrorMessage.lpr(17,17) Hint: Parameter "x" not used
ParameterTypeErrorMessage.lpr(17,25) Hint: Parameter "z" not used
ParameterTypeErrorMessage.lpr(22,9) Error: Incompatible type for arg no. 2: Got "ShortInt", expected "R2"
ParameterTypeErrorMessage.lpr(17,11) Hint: Found declaration: Q(var R1;R2);
What is not "user friendly" is that, the compiler points out that "B" is the wrong type first, instead of "x".  In addition to that, the compiler reports the error column as the column where the close parenthesis is located instead of the column where "B" is located.

It would be nicer (and more "human") to point to "x" first and have the column number point to the parameter instead of whatever follows it.

FPC v3.0.4 and Lazarus 1.8.2 on Windows 7 64bit.

winni

  • Hero Member
  • *****
  • Posts: 1754
Re: Somewhat unusual error message
« Reply #1 on: February 05, 2020, 07:15:21 pm »
Hi!

Do you realy want to open pandora's box about the sense and the non-sense of the compiler messages? You are about to start a neverending thread with a lot of fire!

I wish you good luck!

Winni

440bx

  • Hero Member
  • *****
  • Posts: 1988
Re: Somewhat unusual error message
« Reply #2 on: February 05, 2020, 07:22:05 pm »
Do you realy want to open pandora's box about the sense and the non-sense of the compiler messages? You are about to start a neverending thread with a lot of fire!
Most definitely not.  As I said in my opening statement, it is just FYI.
FPC v3.0.4 and Lazarus 1.8.2 on Windows 7 64bit.

HeavyUser

  • Sr. Member
  • ****
  • Posts: 310
Re: Somewhat unusual error message
« Reply #3 on: February 05, 2020, 09:48:19 pm »
I though that the documentation mentioned that the parameter validation/evaluation is from right to left or my memory fails me?

440bx

  • Hero Member
  • *****
  • Posts: 1988
Re: Somewhat unusual error message
« Reply #4 on: February 05, 2020, 10:41:57 pm »
I though that the documentation mentioned that the parameter validation/evaluation is from right to left or my memory fails me?
I did not find  any mention in the FPC manuals of the sequence in which parameters are validated.  I did find information about the evaluation order of terms in an expression but, that's a different thing.

Anyway, regardless of how FPC internally chooses to validate parameters, it would be nicer if errors were emitted left to right because that's how we (many/most) humans read.  It would just be "friendlier" and more intuitive than fixing the problem with the second (in this case) parameter only to get an error about the first parameter on the next compile.
FPC v3.0.4 and Lazarus 1.8.2 on Windows 7 64bit.

winni

  • Hero Member
  • *****
  • Posts: 1754
Re: Somewhat unusual error message
« Reply #5 on: February 05, 2020, 11:59:00 pm »
Hi!

Code: Text  [Select][+][-]
  1. [b]Order of parameter evaluation[/b]
  2.  
  3. Delphi guarantees that all parameters are evaluated from left to right.
  4. FPC makes no such guarantee, and can evaluate parameters in any
  5. order it wants in order to generate optimal code.
  6.  
  7.  
  8.  

from:

https://wiki.freepascal.org/Code_Conversion_Guide#Order_of_parameter_evaluation


C evaluates from right to left.

Winni

440bx

  • Hero Member
  • *****
  • Posts: 1988
Re: Somewhat unusual error message
« Reply #6 on: February 06, 2020, 12:28:03 am »
Code: Text  [Select][+][-]
  1. [b]Order of parameter evaluation[/b]
  2.  
  3. Delphi guarantees that all parameters are evaluated from left to right.
  4. FPC makes no such guarantee, and can evaluate parameters in any
  5. order it wants in order to generate optimal code.
  6.  
Hello Winni, thank you for that reference.  I searched the user's guide and the programmer's guide and didn't find that information there.  It might be a good thing to add to either manual.

Not to nitpick but, parameter evaluation and parameter validation are not the same thing.  When the compiler is parsing the source code it is _validating_ and, it normally does that either left to right or right to left depending on the choice of algorithms.  Once the parameters are validated (e.g, types match and references match - i.e, var/values) then the compiler is free to evaluate however it wants. (that said, it usually does both simultaneously... oh well.)

At any rate, it would be nicer if errors where reported left to right whenever possible.  That would avoid getting an error on parameter n then an error on parameter (n-1) in the following compile (that said, cultures that read right to left might consider it a nice feature ;) )


FPC v3.0.4 and Lazarus 1.8.2 on Windows 7 64bit.

winni

  • Hero Member
  • *****
  • Posts: 1754
Re: Somewhat unusual error message
« Reply #7 on: February 06, 2020, 01:44:46 am »
Hi!

But now you face the fact with the two different types of aliens with rare contact:

On the one planet the compiler builders. And on the other planet the designers of the user interface. The seldom take attention of each other.

And the situation is getting worse:

In the 90th the publishing houses and the translation companies all had some "technical editors". At the end of that decade this job was abolished : They earned too much money.

Now the gap between code and human interface is getting bigger and bigger.

And I don't want no "String exceeds line" from the compiler but:
"Idiot - you forgot the ' at the end of the string."

But that's a long story.

Winni
« Last Edit: February 06, 2020, 02:10:38 am by winni »

HeavyUser

  • Sr. Member
  • ****
  • Posts: 310
Re: Somewhat unusual error message
« Reply #8 on: February 06, 2020, 02:06:27 am »
Not to nitpick but, parameter evaluation and parameter validation are not the same thing.  When the compiler is parsing the source code it is _validating_ and, it normally does that either left to right or right to left depending on the choice of algorithms.  Once the parameters are validated (e.g, types match and references match - i.e, var/values) then the compiler is free to evaluate however it wants. (that said, it usually does both simultaneously... oh well.)

At any rate, it would be nicer if errors where reported left to right whenever possible.  That would avoid getting an error on parameter n then an error on parameter (n-1) in the following compile (that said, cultures that read right to left might consider it a nice feature ;) )
You assume that after an evaluation fails the compiler continues to the rest. That's a bit irrational in my experience, evaluation failure stops the compilation process.

440bx

  • Hero Member
  • *****
  • Posts: 1988
Re: Somewhat unusual error message
« Reply #9 on: February 06, 2020, 03:10:34 am »
You assume that after an evaluation fails the compiler continues to the rest. That's a bit irrational in my experience, evaluation failure stops the compilation process.
No.  If parameter _validation_ fails then the compilation stops.  It is quite common (actually, likely the most common case) for the compiler not to be able to evaluate a parameter, it can only evaluate constants and most of the time, what's passed as a parameter is a variable which, being a variable, cannot be evaluated at compile time.
FPC v3.0.4 and Lazarus 1.8.2 on Windows 7 64bit.

 

TinyPortal © 2005-2018