View Issue Details

IDProjectCategoryView StatusLast Update
0030109LazarusIDEpublic2020-02-13 06:32
ReporterlksAssigned To 
PrioritynormalSeverityminorReproducibilityalways
Status confirmedResolutionopen 
Product Version1.7 (SVN)Product Build 
Target VersionFixed in Version 
Summary0030109: IDE editor: {$if} doesn't evaluate constants
DescriptionExample:

const HIGHLIGHTED = 1;
{$if HIGHLIGHTED = 1}
// this should appear in normal font, but displays in lighter font
{$else}
// this should appear in lighter font, but displays in normal font
{$endif}
TagsNo tags attached.
Fixed in Revision
LazTarget-
Widgetset
Attached Files
  • 0001-DebugLn-for-issue-30109.patch (1,721 bytes)
    From e047221995fc499e89c90ae571e92d8b798565c5 Mon Sep 17 00:00:00 2001
    From: juha <juha.manninen62@gmail.com>
    Date: Fri, 14 Sep 2018 14:26:50 +0300
    Subject: [PATCH] DebugLn for issue 30109.
    
    ---
     components/codetools/linkscanner.pas | 7 +++++--
     1 file changed, 5 insertions(+), 2 deletions(-)
    
    diff --git a/components/codetools/linkscanner.pas b/components/codetools/linkscanner.pas
    index 200c7ce23..5a17bcedb 100644
    --- a/components/codetools/linkscanner.pas
    +++ b/components/codetools/linkscanner.pas
    @@ -3607,6 +3607,7 @@ begin
       if FSkippingDirectives<>lssdNone then exit(true);
       ReadSpace;
       VariableName:=ReadUpperIdentifier;
    +  DebugLn(['TLinkScanner.IfdefDirective: VariableName=', VariableName]);
       if (VariableName<>'') and (not Values.IsDefined(VariableName)) then
         SkipTillEndifElse(lssdTillElse);
       Result:=true;
    @@ -4651,14 +4652,16 @@ function TLinkScanner.InternalIfDirective: boolean;
     
     var
       ExprResult: Boolean;
    +  Expr: String;
     begin
    -  //DebugLn(['TLinkScanner.InternalIfDirective FSkippingDirectives=',ord(FSkippingDirectives),' IfLevel=',IfLevel]);
    +  DebugLn(['TLinkScanner.InternalIfDirective FSkippingDirectives=', ord(FSkippingDirectives),', IfLevel=',IfLevel]);
       inc(SrcPos);
       if SrcPos>SrcLen then
         RaiseMissingExpr;
       ExprResult:=Values.EvalBoolean(@Src[SrcPos],CommentInnerEndPos-SrcPos);
       Result:=true;
    -  //DebugLn(['TLinkScanner.InternalIfDirective ExprResult=',ExprResult]);
    +  Expr:=Copy(Src,SrcPos,CommentInnerEndPos-SrcPos);
    +  DebugLn(['TLinkScanner.InternalIfDirective: Expr=',Expr,', ExprResult=',ExprResult]);
       if Values.ErrorPosition>=0 then begin
         inc(SrcPos,Values.ErrorPosition);
         RaiseException(20170422130200,Values.ErrorMsg)
    -- 
    2.18.0
    
    

Relationships

has duplicate 0032950 resolvedBart Broersma Code editor always displayes the code within {$if CONST_NAME = NNN} ... {$endif} as inactive 
has duplicate 0033715 closedBart Broersma Incorrect syntax highlighting of $IF directives 
has duplicate 0036612 resolvedBart Broersma Codetool parses "{$IF ident > n}" wrong / Lazarus editor grayed out wrong section of const conditional compilation 
related to 0030214 assignedMattias Gaertner IFDEF + numeric identifier is always TRUE in IDE 
related to 0029998 new Wrong color of conditional-compile code 
related to 0034649 resolvedBart Broersma Source Code Editor shows inverted interpretation of $if statements 

Activities

Bart Broersma

2016-05-22 16:14

developer   ~0092688

The same goes for {$if DECLARED(foo_bar_test)} syntax.
It will always be shown in normal font (as if evaluated to TRUE).

lks

2018-03-30 17:43

reporter   ~0107467

If somebody can point me to where to look, I am happy to take a shot at fixing this problem.

Fr0sT

2018-09-14 10:20

reporter   ~0110734

Last edited: 2018-09-14 10:20

View 2 revisions

Any updates on this? Issue still persists on 1.9.0.
Moreover this breaks coding process raising an error when one executes code completion

~~~
  {$IF DECLARED(TFooBarClass)}
  TSomeClass = class(TFooBarClass);
  {$ELSE}
  TSomeClass = class(TComponent);
  {$IFEND}

...

var ds: TSomeClass;
begin
  ds. <= press Ctrl+Space here - get Error: identifier not found: TFooBarClass

Juha Manninen

2018-09-14 13:31

developer  

0001-DebugLn-for-issue-30109.patch (1,721 bytes)
From e047221995fc499e89c90ae571e92d8b798565c5 Mon Sep 17 00:00:00 2001
From: juha <juha.manninen62@gmail.com>
Date: Fri, 14 Sep 2018 14:26:50 +0300
Subject: [PATCH] DebugLn for issue 30109.

---
 components/codetools/linkscanner.pas | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/components/codetools/linkscanner.pas b/components/codetools/linkscanner.pas
index 200c7ce23..5a17bcedb 100644
--- a/components/codetools/linkscanner.pas
+++ b/components/codetools/linkscanner.pas
@@ -3607,6 +3607,7 @@ begin
   if FSkippingDirectives<>lssdNone then exit(true);
   ReadSpace;
   VariableName:=ReadUpperIdentifier;
+  DebugLn(['TLinkScanner.IfdefDirective: VariableName=', VariableName]);
   if (VariableName<>'') and (not Values.IsDefined(VariableName)) then
     SkipTillEndifElse(lssdTillElse);
   Result:=true;
@@ -4651,14 +4652,16 @@ function TLinkScanner.InternalIfDirective: boolean;
 
 var
   ExprResult: Boolean;
+  Expr: String;
 begin
-  //DebugLn(['TLinkScanner.InternalIfDirective FSkippingDirectives=',ord(FSkippingDirectives),' IfLevel=',IfLevel]);
+  DebugLn(['TLinkScanner.InternalIfDirective FSkippingDirectives=', ord(FSkippingDirectives),', IfLevel=',IfLevel]);
   inc(SrcPos);
   if SrcPos>SrcLen then
     RaiseMissingExpr;
   ExprResult:=Values.EvalBoolean(@Src[SrcPos],CommentInnerEndPos-SrcPos);
   Result:=true;
-  //DebugLn(['TLinkScanner.InternalIfDirective ExprResult=',ExprResult]);
+  Expr:=Copy(Src,SrcPos,CommentInnerEndPos-SrcPos);
+  DebugLn(['TLinkScanner.InternalIfDirective: Expr=',Expr,', ExprResult=',ExprResult]);
   if Values.ErrorPosition>=0 then begin
     inc(SrcPos,Values.ErrorPosition);
     RaiseException(20170422130200,Values.ErrorMsg)
-- 
2.18.0

Juha Manninen

2018-09-14 13:39

developer   ~0110745

Last edited: 2018-09-14 13:55

View 3 revisions

> If somebody can point me to where to look, I am happy to take a shot at fixing this problem.

Function TLinkScanner.InternalIfDirective. It uses class TExpressionEvaluator.
ExprResult:=Values.EvalBoolean(...) seems an essential call.
Ask questions in Lazarus mailing list. First study the code well so that you can ask relevant questions. Mattias and maybe Martin know the code best.
See also the related issues.

I uploaded a patch that adds DebugLn() calls to get you started. DebugLn() is a good and powerful way to debug the IDE.

Issue History

Date Modified Username Field Change
2016-05-08 01:03 lks New Issue
2016-05-08 23:40 Bart Broersma LazTarget => -
2016-05-08 23:40 Bart Broersma Status new => confirmed
2016-05-09 09:12 Ondrej Pokorny OS OSX =>
2016-05-09 09:12 Ondrej Pokorny OS Version 10.11 =>
2016-05-09 09:12 Ondrej Pokorny Platform darwin =>
2016-05-09 09:12 Ondrej Pokorny Summary {$if} displays the wrong way in conditional expressions => IDE editor: {$if} doesn't evaluate constants
2016-05-22 16:14 Bart Broersma Note Added: 0092688
2016-05-31 22:35 Bart Broersma Relationship added related to 0030214
2016-08-22 17:11 Bart Broersma Relationship added related to 0029998
2018-01-12 15:02 Bart Broersma Relationship added has duplicate 0032950
2018-03-30 17:43 lks Note Added: 0107467
2018-05-09 19:09 Bart Broersma Relationship added has duplicate 0033715
2018-09-14 10:20 Fr0sT Note Added: 0110734
2018-09-14 10:20 Fr0sT Note Edited: 0110734 View Revisions
2018-09-14 13:31 Juha Manninen File Added: 0001-DebugLn-for-issue-30109.patch
2018-09-14 13:39 Juha Manninen Note Added: 0110745
2018-09-14 13:40 Juha Manninen Note Edited: 0110745 View Revisions
2018-09-14 13:55 Juha Manninen Note Edited: 0110745 View Revisions
2018-12-05 12:27 Martin Friebe Relationship added related to 0034649
2020-01-21 05:28 Martin Friebe Relationship added has duplicate 0036612