View Issue Details

IDProjectCategoryView StatusLast Update
0038504FPCCompilerpublic2021-02-21 19:47
ReporterJohn Assigned ToFlorian  
PrioritynormalSeverityminorReproducibilityhave not tried
Status resolvedResolutionfixed 
Platformx64OSWindows 10 
Product Version3.2.0 
Fixed in Version3.3.1 
Summary0038504: Implicit Typecast Failure
DescriptionIn the Free Pascal IDE, a global variable is defined as char. In a procedure, an attempt is made to set the variable to null using VariableName := '';. A compiler error is returned: Incompatible types: got "Constant String" expected "Char". An explicit typecast works as expected.

Steps To ReproduceVar
  MyVar : char;

Procedure MyProc;
Begin
  MyVar := ''; (* <-- two single-quotes *)
End;


Begin
End.
TagsNo tags attached.
Fixed in Revision48759
FPCOldBugId
FPCTarget-
Attached Files

Activities

Jonas Maebe

2021-02-17 20:32

manager   ~0128985

The error is that the explicit typecast is accepted: char('') is invalid. The representation of a nul-character is # 0 (without the space; space added because otherwise mantis interprets it as a reference to another bug).

Kai Burghardt

2021-02-18 01:40

reporter   ~0128988

Huh. If i print pTypeInfo(typeInfo(''))^.kind, I see it’s a tkArray, so I guess it’s a fixed-length shortString, I can even do things like ord(''[0]), i.e. reading the “length” Byte, which for this particular case coincides with the presumably intended #‍0. [Accordingly ord('Foo'[0]) would return 3.]

So, as far as I understand the “problem”, everything is alright and correct. Note, an explicit typecast _disables_ all kinds of checks for the entire LOC so it’ll never complain about nothing.

Sven Barth

2021-02-18 09:11

manager   ~0128989

The length byte of Ord(''[0]) is 0, thus there is by definition no data that could be converted to a Char and the terminating #0 is only there so that it can be used for a PChar, it's not considered part of the string data.

Bart Broersma

2021-02-18 18:34

reporter   ~0128998

IIRC then you can only cast something to Char if the something is ordinal.
A string is not ordinal (not even an empty string is), so the cast should be illegal.

Florian

2021-02-21 19:47

administrator   ~0129070

The type cast is not accepted anymore as it makes no sense. It was equal to the valid statement <char var.>:=#0;

Issue History

Date Modified Username Field Change
2021-02-17 20:29 John New Issue
2021-02-17 20:32 Jonas Maebe Note Added: 0128985
2021-02-18 01:40 Kai Burghardt Note Added: 0128988
2021-02-18 09:11 Sven Barth Note Added: 0128989
2021-02-18 18:34 Bart Broersma Note Added: 0128998
2021-02-21 19:47 Florian Assigned To => Florian
2021-02-21 19:47 Florian Status new => resolved
2021-02-21 19:47 Florian Resolution open => fixed
2021-02-21 19:47 Florian Fixed in Version => 3.3.1
2021-02-21 19:47 Florian Fixed in Revision => 48759
2021-02-21 19:47 Florian FPCTarget => -
2021-02-21 19:47 Florian Note Added: 0129070