View Issue Details

IDProjectCategoryView StatusLast Update
0035248FPCCompilerpublic2019-10-06 17:51
ReporterThaddy de Koning Assigned To 
Status newResolutionopen 
Product Version3.3.1 
Summary0035248: Operator overloading: a LEFT literal string + a RIGHT literal number fails with Error: Incompatible types. Which is not correct.
Descriptionconstruct.pas(26,23) Error: Incompatible types: got "LongInt" expected "ShortString"

Note all other string types as well: both Ansi and Unicode.
Strange thing is that all other combinations pass all tests.
Below is a test program that I have tested with on WIN-x86_64 and Rasbian.

I could reduce it to just the one case:Literal string left, variable integer right.
Steps To Reproduce{$MODE OBJFPC}

operator + (Left: LongInt; const Right: string): string;
operator + (const Left: string; Right: LongInt): string;
// V = variable L is literal
// S = string I is integer
  Text: string = 'text';
  Number: LongInt = 123456;
  Writeln(Text + Number); // PASS: VS+VI
  Writeln(Number + Text); // PASS: VI+VS
  Writeln(789012 + Text); // PASS: LI+VS
  Writeln(Text+789012); // PASS: VS+LI
  //---- problem here...
  Writeln('else text'+Number);// FAIL LS+VI : fails only on LEFT string literals + non-literal number with all string types
  //---- end of problem
  Writeln(Number + 'other text'); //PASS: VI+LS
  Writeln(string('else text')+Number); //PASS: CAST(LS)+VI
  writeln(789012 + 'other text'); // PASS: LI+LS
  writeln('other text',789012); // PASS: LS+LI
Additional InformationBased on discussion here:,44713.0.html
TagsNo tags attached.
Fixed in Revision
Attached Files


Thaddy de Koning

2019-03-19 11:53

reporter   ~0114922

Last edited: 2019-03-19 11:59

View 2 revisions

PLZ correct:
0035248: Operator overloading: a LEFT literal string + a RIGHT NON-literal number fails with Error: Incompatible types. Which is not correct.
(I can't edit, but: Plz add NON- to the summary: it is left literal string vs right variable number that fails the tests)

Thaddy de Koning

2019-03-19 12:17

reporter   ~0114923

Also note I made a typo:
 writeln('other text',789012); // PASS: LS+LI

Doesn't pass when written like:
 writeln('other text'+ 789012); // FAIL: LS+LI

So both L-R fail.

Bart Broersma

2019-04-03 16:33

reporter   ~0115196

Maybe related to 0029460?

Bart Broersma

2019-10-06 13:57

reporter   ~0118377

My proposed patch for 0029460 unfortunately does not fix this issue :-(

Thaddy de Koning

2019-10-06 17:51

reporter   ~0118382

Last edited: 2019-10-06 17:51

View 2 revisions

This still works (specified stringtype):
operator = (z1: ansistring; z2 : longint) b : boolean;
  b := false;

Issue History

Date Modified Username Field Change
2019-03-19 11:52 Thaddy de Koning New Issue
2019-03-19 11:53 Thaddy de Koning Note Added: 0114922
2019-03-19 11:59 Thaddy de Koning Note Edited: 0114922 View Revisions
2019-03-19 12:17 Thaddy de Koning Note Added: 0114923
2019-04-03 16:33 Bart Broersma Note Added: 0115196
2019-10-06 13:57 Bart Broersma Note Added: 0118377
2019-10-06 17:51 Thaddy de Koning Note Added: 0118382
2019-10-06 17:51 Thaddy de Koning Note Edited: 0118382 View Revisions