View Issue Details

IDProjectCategoryView StatusLast Update
0034333FPCCompilerpublic2018-09-29 10:14
ReporterOndrej PokornyAssigned ToSven Barth 
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Product Version3.3.1Product Build 
Target VersionFixed in Version3.3.1 
Summary0034333: Copy(S, 1, 2, 3) wrong error message
DescriptionIf you use the ShortString-variant of Copy with wrong parameter count, you get a "Type mismatch" compiler error instead of "wrong number of parameters".
Steps To Reproduceprogram Project1;
var
  S: ShortString;
begin
  S := Copy(S, 1, 2, 3); // << project1.lpr(5,14) Error: Type mismatch
end.
Additional InformationPatch attached.
TagsNo tags attached.
Fixed in Revision39817,39836
FPCOldBugId
FPCTarget
Attached Files
  • copy-1.patch (458 bytes)
    Index: compiler/ninl.pas
    ===================================================================
    --- compiler/ninl.pas	(revision 39802)
    +++ compiler/ninl.pas	(working copy)
    @@ -1837,7 +1837,7 @@
                if (counter=3) or (counter=2) then
                  resultdef:=cshortstringtype
                else
    -             CGMessagePos(ppn.left.fileinfo,type_e_mismatch);
    +             CGMessage1(parser_e_wrong_parameter_size,'Copy');
              end;
           end;
     
    
    copy-1.patch (458 bytes)

Activities

Ondrej Pokorny

2018-09-25 21:33

reporter  

copy-1.patch (458 bytes)
Index: compiler/ninl.pas
===================================================================
--- compiler/ninl.pas	(revision 39802)
+++ compiler/ninl.pas	(working copy)
@@ -1837,7 +1837,7 @@
            if (counter=3) or (counter=2) then
              resultdef:=cshortstringtype
            else
-             CGMessagePos(ppn.left.fileinfo,type_e_mismatch);
+             CGMessage1(parser_e_wrong_parameter_size,'Copy');
          end;
       end;
 
copy-1.patch (458 bytes)

Marco van de Voort

2018-09-26 10:45

manager   ~0111024

It probably matches an overload for multi dimensional arrays ?

Then S is the wrong type.

Ondrej Pokorny

2018-09-26 11:01

reporter   ~0111025

> It probably matches an overload for multi dimensional arrays ?
There is no overload for multi dimensional arrays or anything else with 4 or more parameters - in this case the "type mismatch" error is wrong.

Yes, there is an overload with 1 parameter for multi dimensional arrays that is not valid for ShortString: S := Copy(S);
In this case both error messages are acceptable (either the ShortString is wrong or the parameter count is wrong).

But the "wrong number of parameters" is better anyway - it is more probable that you typed a wrong number of parameters and the ShortString parameter is correct. To fix the error you have to add the second parameter.

Check the code:
            if (counter=3) or (counter=2) then
              resultdef:=cshortstringtype
            else
              CGMessagePos(ppn.left.fileinfo,type_e_mismatch);

--> you check for the parameter count and when it doesn't match you emit "type mismatch"? It doesn't make sense.

"type mismatch" error makes sense only if you check the type.

Sven Barth

2018-09-26 23:34

manager   ~0111042

I've improved the error reporting to be more similar to the one from Insert/Delete/Concat.

Please test and close if okay.

Ondrej Pokorny

2018-09-27 00:12

reporter   ~0111043

I still get an "Error: Type mismatch" on Copy with 4 arguments. Delete shows a "Wrong number of parameters" instead. Simple test:

program Project1;
var
  S: ShortString;
begin
  Delete(S, 1, 2, 3); // << project1.lpr(5,3) Error: Wrong number of parameters specified for call to "Delete"
  S := Copy(S, 1, 2, 3); // << project1.lpr(6,14) Error: Type mismatch
end.

Sven Barth

2018-09-27 21:45

manager   ~0111055

*sigh*

Please test and close if okay

Ondrej Pokorny

2018-09-29 10:14

reporter   ~0111072

Yes, you fixed the 4-parameter error message, but the 1-parameter message is still wrong (string/ShortString errors differ):

program Project1;
var
  AS: AnsiString;
  SS: ShortString;
begin
  AS := Copy(AS); // << project1.lpr(7,8) Error: Wrong number of parameters specified for call to "Copy"
  SS := Copy(SS); // << project1.lpr(7,16) Error: Type mismatch
end.

But I assume you have better things to do, so closing :)

Issue History

Date Modified Username Field Change
2018-09-25 21:33 Ondrej Pokorny New Issue
2018-09-25 21:33 Ondrej Pokorny File Added: copy-1.patch
2018-09-26 10:45 Marco van de Voort Note Added: 0111024
2018-09-26 11:01 Ondrej Pokorny Note Added: 0111025
2018-09-26 23:34 Sven Barth Fixed in Revision => 39817
2018-09-26 23:34 Sven Barth Note Added: 0111042
2018-09-26 23:34 Sven Barth Status new => resolved
2018-09-26 23:34 Sven Barth Fixed in Version => 3.3.1
2018-09-26 23:34 Sven Barth Resolution open => fixed
2018-09-26 23:34 Sven Barth Assigned To => Sven Barth
2018-09-27 00:12 Ondrej Pokorny Note Added: 0111043
2018-09-27 00:12 Ondrej Pokorny Status resolved => feedback
2018-09-27 00:12 Ondrej Pokorny Resolution fixed => reopened
2018-09-27 21:45 Sven Barth Fixed in Revision 39817 => 39817,39836
2018-09-27 21:45 Sven Barth Note Added: 0111055
2018-09-27 21:45 Sven Barth Status feedback => resolved
2018-09-27 21:45 Sven Barth Resolution reopened => fixed
2018-09-29 10:14 Ondrej Pokorny Note Added: 0111072
2018-09-29 10:14 Ondrej Pokorny Status resolved => closed