View Issue Details

IDProjectCategoryView StatusLast Update
0036752LazarusIDEpublic2020-04-25 09:25
ReporterTrevor Roydhouse Assigned ToDmitry Boyarintsev  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionreopened 
PlatformApple Mac miniOSmacOS 
Target Version2.0.8 
Summary0036752: Codetools do not accept "cblock" modifier with {$modeswitch cblocks}
DescriptionAttempts to add any form method to a project results in an error and the file AudioComponents.pas is opened in the IDE editor complaining of a CodeTools error (see attached image).

Trivial compressed project1.zip demonstrating issue attached. I have the problem with much bigger real projects. This is just the least amount of code to reproduce the error.
Steps To ReproduceTry to add a form method (eg OnCreate etc) to the attached project.
Additional InformationSee Forum: https://forum.lazarus.freepascal.org/index.php/topic,48744.0.html where Dmitry thinks it may be caused by CodeTools not supporting C-blocks related syntax
Tags3.3.1, cocoa, codetools, editor, MacOS
Fixed in Revision62886 63028
LazTarget-
WidgetsetCocoa
Attached Files

Relationships

related to 0036796 closedJuha Manninen "modeswitch arraytodynarray" is still unsupported in Lazarus 

Activities

Trevor Roydhouse

2020-03-03 07:48

reporter  

project1.zip (107,843 bytes)

Juha Manninen

2020-03-03 17:39

developer   ~0121341

Now it can be tested only by people with a Mac.
Can the problematic syntax be isolated into simple cross-platform demo program?
The issue would get more testers then.

Bart Broersma

2020-03-07 15:38

developer   ~0121433

If this is about c-blocks, then copy the code example from https://svn.freepascal.org/svn/fpc/trunk/tests/test/tblock2.pp into a unit's form and see how CodeTools handle it.
I cannot test that since I cannot build for MacOS.

Juha Manninen

2020-03-08 10:30

developer   ~0121454

The attached patch is a workaround.
With it Codetools accept "cblock" modifier always but it should be accepted only with {$modeswitch cblocks}.
Codetools must be studied more to fix it properly.
0001-CBLOCK-for-CodeTools.patch (1,961 bytes)   
From 708455a6e86d6d4f2f81453281a1498471e07f66 Mon Sep 17 00:00:00 2001
From: juha <juha.manninen62@gmail.com>
Date: Sun, 8 Mar 2020 02:22:07 +0200
Subject: [PATCH] CBLOCK for CodeTools

---
 components/codetools/keywordfunclists.pas | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/components/codetools/keywordfunclists.pas b/components/codetools/keywordfunclists.pas
index 7f22ad48f..ef7538ba4 100644
--- a/components/codetools/keywordfunclists.pas
+++ b/components/codetools/keywordfunclists.pas
@@ -941,6 +941,7 @@ begin
     Add('VARARGS'      ,{$ifdef FPC}@{$endif}AllwaysTrue); // kylix
     Add('VECTORCALL'   ,{$ifdef FPC}@{$endif}AllwaysTrue);
     Add('WEAKEXTERNAL' ,{$ifdef FPC}@{$endif}AllwaysTrue);
+    Add('CBLOCK'       ,{$ifdef FPC}@{$endif}AllwaysTrue);
     Add('['            ,{$ifdef FPC}@{$endif}AllwaysTrue);
   end;
   
@@ -966,6 +967,7 @@ begin
     Add('EXPERIMENTAL' ,{$ifdef FPC}@{$endif}AllwaysTrue);
     Add('LIBRARY'      ,{$ifdef FPC}@{$endif}AllwaysTrue);
     Add('IS'           ,{$ifdef FPC}@{$endif}AllwaysTrue);
+    Add('CBLOCK'       ,{$ifdef FPC}@{$endif}AllwaysTrue);
   end;
 
   IsKeyWordProcedureAnonymousSpecifier:=TKeyWordFunctionList.Create('IsKeyWordProcedureAnonymousSpecifier');
@@ -985,6 +987,7 @@ begin
     Add('STDCALL'      ,{$ifdef FPC}@{$endif}AllwaysTrue);
     Add('VARARGS'      ,{$ifdef FPC}@{$endif}AllwaysTrue);
     Add('VECTORCALL'   ,{$ifdef FPC}@{$endif}AllwaysTrue);
+    Add('CBLOCK'       ,{$ifdef FPC}@{$endif}AllwaysTrue);
   end;
 
   IsKeyWordCallingConvention:=TKeyWordFunctionList.Create('IsKeyWordCallingConvention');
@@ -997,6 +1000,7 @@ begin
     Add('MWPASCAL'     ,{$ifdef FPC}@{$endif}AllwaysTrue);
     Add('POPSTACK'     ,{$ifdef FPC}@{$endif}AllwaysTrue);
     Add('VECTORCALL'   ,{$ifdef FPC}@{$endif}AllwaysTrue);
+    Add('CBLOCK'       ,{$ifdef FPC}@{$endif}AllwaysTrue);
     // Note: 'inline' and 'is nested' are not a calling specifiers
   end;
 
-- 
2.25.1

Juha Manninen

2020-03-08 19:14

developer   ~0121469

A dummy question: What does the "cblock" modifier do? Can it also be with normal functions / procedures / methods?
Or, is it always with a type definition "reference to"?
I guess "reference to" is about anonymous function stuff. Maybe I should learn it.

Sven Barth

2020-03-09 11:44

manager   ~0121489

The cblock modifier can only be used for function references (reference to procedure/function) and is required to indicate that the variable in question is for the macOS C-block functionality which is a bit similar to closures / anonymous functions, but different enough to need a different handling (and as FPC does not support anonymous functions yet you need to use nested functions for this).

Hans Luijten

2020-03-10 13:05

reporter   ~0121531

Ran into the same issue and the patch (even though it is temporary fix) made the IDE usable again.
Thanks Juha!

Trevor Roydhouse

2020-03-11 01:24

reporter   ~0121545

My current workaround is to comment out MacOSAll in the Uses clause, add the methods, then uncomment MacOSAll and compile.

Dmitry Boyarintsev

2020-04-05 06:33

developer   ~0121917

patch was too broad. I did add "cblocks" only as procedural type modifier. This should be enough.

Dmitry Boyarintsev

2020-04-05 06:33

developer   ~0121918

please test and close if ok

Trevor Roydhouse

2020-04-17 13:31

reporter   ~0122190

r63006 compiled with:

svn cleanup --remove-unversioned
make distclean all LCL_PLATFORM=cocoa CPU_TARGET=x86_64 bigide

results in these errors:

Compiling cocoaprivate.pas
cocoaprivate.pas(1386,3) Note: Local variable "ctx" is assigned but never used
Assembling (pipe) ../../units/x86_64-darwin/cocoa/cocoaprivate.s
Compiling cocoawsmenus.pas
Compiling cocoawscommon.pas
Compiling cocoacaret.pas
Assembling (pipe) ../../units/x86_64-darwin/cocoa/cocoacaret.s
Compiling cocoascrollers.pas
cocoascrollers.pas(53,15) Error: There is no method in an ancestor class to be overridden: "setDocumentView(id);"
cocoascrollers.pas(53,15) Error: Objective-C messages require their Objective-C selector name to be specified using the "message" directive.
cocoascrollers.pas(53,15) Error: Mismatch between number of declared parameters and number of colons in message string.
cocoascrollers.pas(159,1) Fatal: There were 3 errors compiling module, stopping
Fatal: Compilation aborted
make[3]: *** [../lcl.ppu] Error 1
make[2]: *** [cocoa_all] Error 2
make[1]: *** [interfaces] Error 2
make: *** [lcl] Error 2

Dmitry Boyarintsev

2020-04-17 13:44

developer   ~0122192

did you update cocoa sources from trunk as well?

Trevor Roydhouse

2020-04-17 14:12

reporter   ~0122196

Yes, everything is up to date to 17 April.

Dmitry Boyarintsev

2020-04-17 16:07

developer   ~0122198

what's your fpc version?

Trevor Roydhouse

2020-04-17 16:15

reporter   ~0122199

Lazarus trunk r63006 2020-04-17 19:32:13 +1000 (Fri, 17 Apr 2020)
FPC trunk r44744 2020-04-17 10:15:30 +1000 (Fri, 17 Apr 2020)

Dmitry Boyarintsev

2020-04-17 16:23

developer   ~0122200

please try the patch attached.

Note, i didn't really try if it compiles, but the idea is the following.
The declaration setDocumentView() varies between FPC versions
FPC before 3.2.0 is using NSView as the parameter type
FPC 3.2.0 is being released with "id" as the parameter type
FPC after 3.2.0 is being released with "NSView" (?) as the parameter type
cocoascrollers.pas.diff (1,159 bytes)   
Index: cocoascrollers.pas
===================================================================
--- cocoascrollers.pas	(revision 63006)
+++ cocoascrollers.pas	(working copy)
@@ -31,6 +31,7 @@
   cocoa_extra, CocoaPrivate;
 
 type
+  TSetDocumentViewType = {$if FPC_FULLVERSION = 30200}id{$else}NSView{$endif};
 
   { TCocoaScrollView }
 
@@ -50,9 +51,7 @@
     procedure resetCursorRects; override;
     function lclClientFrame: TRect; override;
     function lclContentView: NSView; override;
-    procedure setDocumentView(aView:
-      {$if FPC_FULLVERSION < 30200}NSView{$else}id{$endif}
-    ); override;
+    procedure setDocumentView(aView:  TSetDocumentViewType); override;
     procedure scrollContentViewBoundsChanged(notify: NSNotification); message 'scrollContentViewBoundsChanged:';
     procedure resetScrollRect; message 'resetScrollRect';
 
@@ -648,7 +647,7 @@
   Result:=documentView;
 end;
 
-procedure TCocoaScrollView.setDocumentView(aView: {$if FPC_FULLVERSION < 30200}NSView{$else}id{$endif});
+procedure TCocoaScrollView.setDocumentView(aView: TSetDocumentViewType);
 begin
   inherited setDocumentView(aView);
   resetScrollRect;
cocoascrollers.pas.diff (1,159 bytes)   

Trevor Roydhouse

2020-04-18 02:24

reporter   ~0122217

Success. Your patch resolved the compilation issue and I can confirm that the issue is also resolved :-)

Dmitry Boyarintsev

2020-04-20 05:11

developer   ~0122264

the patch has been applied (to trunk only)
please test and close if ok

Trevor Roydhouse

2020-04-20 12:50

reporter   ~0122268

Tested AOK. Closing. Thanks!

Trevor Roydhouse

2020-04-25 09:25

reporter   ~0122398

Fixed.

Issue History

Date Modified Username Field Change
2020-03-03 07:48 Trevor Roydhouse New Issue
2020-03-03 07:48 Trevor Roydhouse File Added: Screen Shot 2020-03-03 at 5.35.36 pm.png
2020-03-03 07:48 Trevor Roydhouse File Added: project1.zip
2020-03-03 07:55 Trevor Roydhouse Tag Attached: 3.3.1
2020-03-03 07:55 Trevor Roydhouse Tag Attached: codetools
2020-03-03 07:55 Trevor Roydhouse Tag Attached: editor
2020-03-03 07:55 Trevor Roydhouse Tag Attached: MacOS
2020-03-03 07:55 Trevor Roydhouse Tag Attached: cocoa
2020-03-03 17:39 Juha Manninen Note Added: 0121341
2020-03-07 15:38 Bart Broersma Note Added: 0121433
2020-03-08 10:30 Juha Manninen File Added: 0001-CBLOCK-for-CodeTools.patch
2020-03-08 10:30 Juha Manninen Note Added: 0121454
2020-03-08 10:40 Juha Manninen Summary Unable to add form methods to project => Codetools do not accept "cblock" modifier with {$modeswitch cblocks}
2020-03-08 10:40 Juha Manninen LazTarget => -
2020-03-08 10:40 Juha Manninen Widgetset Cocoa => Cocoa
2020-03-08 19:14 Juha Manninen Note Added: 0121469
2020-03-09 11:44 Sven Barth Note Added: 0121489
2020-03-10 13:05 Hans Luijten Note Added: 0121531
2020-03-11 01:24 Trevor Roydhouse Note Added: 0121545
2020-03-15 18:57 Juha Manninen Relationship added related to 0036796
2020-04-05 05:20 Dmitry Boyarintsev Target Version => 2.0.8
2020-04-05 05:20 Dmitry Boyarintsev Widgetset Cocoa => Cocoa
2020-04-05 06:33 Dmitry Boyarintsev Note Added: 0121917
2020-04-05 06:33 Dmitry Boyarintsev Assigned To => Dmitry Boyarintsev
2020-04-05 06:33 Dmitry Boyarintsev Status new => resolved
2020-04-05 06:33 Dmitry Boyarintsev Resolution open => fixed
2020-04-05 06:33 Dmitry Boyarintsev Fixed in Revision => 62886
2020-04-05 06:33 Dmitry Boyarintsev Widgetset Cocoa => Cocoa
2020-04-05 06:33 Dmitry Boyarintsev Note Added: 0121918
2020-04-17 13:31 Trevor Roydhouse Note Added: 0122190
2020-04-17 13:44 Dmitry Boyarintsev Note Added: 0122192
2020-04-17 14:12 Trevor Roydhouse Note Added: 0122196
2020-04-17 16:07 Dmitry Boyarintsev Status resolved => feedback
2020-04-17 16:07 Dmitry Boyarintsev Resolution fixed => reopened
2020-04-17 16:07 Dmitry Boyarintsev Note Added: 0122198
2020-04-17 16:15 Trevor Roydhouse Note Added: 0122199
2020-04-17 16:15 Trevor Roydhouse Status feedback => assigned
2020-04-17 16:23 Dmitry Boyarintsev File Added: cocoascrollers.pas.diff
2020-04-17 16:23 Dmitry Boyarintsev Note Added: 0122200
2020-04-17 16:23 Dmitry Boyarintsev Status assigned => feedback
2020-04-18 02:24 Trevor Roydhouse Note Added: 0122217
2020-04-18 02:24 Trevor Roydhouse Status feedback => assigned
2020-04-20 05:11 Dmitry Boyarintsev Fixed in Revision 62886 => 62886 63028
2020-04-20 05:11 Dmitry Boyarintsev Widgetset Cocoa => Cocoa
2020-04-20 05:11 Dmitry Boyarintsev Status assigned => resolved
2020-04-20 05:11 Dmitry Boyarintsev Widgetset Cocoa => Cocoa
2020-04-20 05:11 Dmitry Boyarintsev Note Added: 0122264
2020-04-20 12:50 Trevor Roydhouse Note Added: 0122268
2020-04-25 09:25 Trevor Roydhouse Status resolved => closed
2020-04-25 09:25 Trevor Roydhouse Note Added: 0122398