Maurizio Ferreira
Maurizio Ferreira

Reputation: 476

Is this a Delphi Xe8 compiler error?

The following statements compiles correctly:

procedure test ;
var    xx : string;
begin
   xx := 'a' + '}' + 'b';
end;

if you try to comment with a block comment , the compiler erroneously consider the right parenthesis in the text as the end of the comment.

procedure test ;
var    xx : string;
begin
  {   xx := 'a' + '}' + 'b';  }
end;

Am I missing something ?

Upvotes: 0

Views: 174

Answers (1)

David Heffernan
David Heffernan

Reputation: 613461

When you open a comment then the parser simply ignores the text that follows until it finds the appropriate comment termination.

  • In the case of // the termination is the end of the line.
  • In the case of (* the termination is the next instance of *).
  • In the case of { the termination is the next instance of }.

Since the compiler does not parse commented out text, it happens upon your } that is inside a string and determinates that the comment has terminated.

You state:

The compiler erroneously consider the right parenthesis in the text as the end of the comment.

The mis-think in this statement can be seen in the text that I emphasised. Once a comment has started, the parser doesn't care about syntax, about quotes, or indeed anything. All it does is to read the source until it finds the comment termination. It pays no heed to the context in which that comment terminator exists.

Hence this is not a compiler error. The compiler is behaving correctly, as designed.

Upvotes: 8

Related Questions