View Issue Details

IDProjectCategoryView StatusLast Update
0037818LazarusIDEpublic2020-09-27 09:31
ReporterJuha Manninen Assigned To 
PrioritynormalSeverityminorReproducibilityalways
Status newResolutionopen 
Platformx86-64OSManjaro Linux 
Product Version2.1 (SVN) 
Summary0037818: Code completion for "while" and "with" variable wrongly adds a semicolon after "do".
DescriptionIf you have
 var obj: TObject;
typing "with ob", then Ctrl-Space, then Enter to select "obj" completes the code as :
 with obj do;
The semicolon at the end must be removed manually if you want to do anything useful with it.
The same thing happens with a while loop completion. A semicolon is added there, too.

This extra semicolon is nasty because the compiler does not complain about it. A programmer may wonder for long why his code does not work before noticing it.
Additional InformationThis was originally mentioned by user Jo-Anna in #lazarus-ide chat.
TagsNo tags attached.
Fixed in Revision
LazTarget-
Widgetset
Attached Files

Activities

Mattias Gaertner

2020-09-26 13:57

manager   ~0125872

The semicolon is required by fpc unless next token is an "end". Why do you think you must delete it?

Juha Manninen

2020-09-26 21:16

developer   ~0125883

The semicolon should come only after the next expression, not right after the "do".
Assuming var butt: TButton;
Placed in some Form's event handler, these 2 clauses do different things :

  with butt do
    Caption:='butt';

  with butt do;
    Caption:='butt';

The first one is probably what a programmer meant but the compiler does not complain about the second one.

Mattias Gaertner

2020-09-26 21:52

manager   ~0125884

Ah, when changing an existing statement into a with block.
So, it must not insert a semicolon if next statement is indented.

Juha Manninen

2020-09-26 22:13

developer   ~0125885

No. Typing new code.
Assuming you have defined var butt: TButton;
Type new code "with but", then Ctrl-Space, then Enter to select "butt", and you get :
 with butt do;
Note the semicolon at the end. A programmer may fail to notice it and type an expression in the next line thinking it is affected by "with butt do".

Mattias Gaertner

2020-09-26 22:55

manager   ~0125887

1. It seems to me the "fail to notice" argument works here in both ways.
2. Newbies tend to forget semicolons, so in general it is a good thing to auto add them.
3. For-do, while-do also add semicolons. Do you intend to omit them there too?

Juha Manninen

2020-09-27 09:31

developer   ~0125893

I forgot "for-do" loop. Yes, the completion of all 3 (with, while, for) should be consistent.
IMO the semicolon is in a wrong place even if noticed by a programmer. It must be deleted by BackSpace, or the cursor must be moved in front of it and a Space/NewLine must be added.
The semicolon never does anything good when directly following "do" ("do;").
Without the semicolon the programmer could write more code immediately.

Issue History

Date Modified Username Field Change
2020-09-26 13:45 Juha Manninen New Issue
2020-09-26 13:52 Juha Manninen Description Updated View Revisions
2020-09-26 13:52 Juha Manninen LazTarget => -
2020-09-26 13:57 Mattias Gaertner Note Added: 0125872
2020-09-26 14:26 Juha Manninen Description Updated View Revisions
2020-09-26 21:16 Juha Manninen Note Added: 0125883
2020-09-26 21:52 Mattias Gaertner Note Added: 0125884
2020-09-26 22:13 Juha Manninen Note Added: 0125885
2020-09-26 22:55 Mattias Gaertner Note Added: 0125887
2020-09-27 09:31 Juha Manninen Note Added: 0125893