View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0038504 | FPC | Compiler | public | 2021-02-17 20:29 | 2021-02-21 19:47 |
Reporter | John | Assigned To | Florian | ||
Priority | normal | Severity | minor | Reproducibility | have not tried |
Status | resolved | Resolution | fixed | ||
Platform | x64 | OS | Windows 10 | ||
Product Version | 3.2.0 | ||||
Fixed in Version | 3.3.1 | ||||
Summary | 0038504: Implicit Typecast Failure | ||||
Description | In 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 Reproduce | Var MyVar : char; Procedure MyProc; Begin MyVar := ''; (* <-- two single-quotes *) End; Begin End. | ||||
Tags | No tags attached. | ||||
Fixed in Revision | 48759 | ||||
FPCOldBugId | |||||
FPCTarget | - | ||||
Attached Files |
|
|
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). |
|
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. |
|
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. |
|
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. |
|
The type cast is not accepted anymore as it makes no sense. It was equal to the valid statement <char var.>:=#0; |
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 |