Function with untyped parameter accepts retyped constant
Original Reporter info from Mantis: Blaazen @Blaazen
-
Reporter name: Vojtech Cihak
Original Reporter info from Mantis: Blaazen @Blaazen
- Reporter name: Vojtech Cihak
Description:
Function with untyped parameter (i.e procedure Any(const Anything);) accepts retyped constant (i.e. Cardinal([fsItalic, fsBold])).
Without retyping (you can uncomment the line) compilation fails with Error: Variable identifier expected
Steps to reproduce:
program tformal;
{$mode objfpc}
type
TFontStyle = (
fsItalic,
fsBold,
fsUnderlined,
fsStrikeOut
);
TFontStyles = set of TFontStyle;
var aFS: TFontStyles;
procedure Any(const Anything);
begin
aFS:=aFS+TFontStyles(Anything);
end;
procedure DoIt;
begin
//Any([fsItalic, fsBold]); //unit1.pas(31,25) Error: Variable identifier expected
Any(Cardinal([fsItalic, fsBold])); //ok
end;
begin
writeln(Cardinal(aFS));
DoIt;
writeln(Cardinal(aFS));
end.
[v1@nb-msi testset]$ fpc test.pas
Free Pascal Compiler version 3.3.1 [2020/09/04] for x86_64
Copyright (c) 1993-2020 by Florian Klaempfl and others
Target OS: Linux for x86-64
Compiling test.pas
Linking test
29 lines compiled, 0.2 sec
[v1@nb-msi testset]$ ./test
0
3
[v1@nb-msi testset]$
Additional information:
You may look at https://forum.lazarus.freepascal.org/index.php?topic=51516.msg378344#msg378344
where PascalDragon confirmed with 3.0.4, 3.2.0 and 3.3.1.
Mantis conversion info:
- Mantis ID: 37796
- OS: Linux
- OS Build: Chakra 64bit
- Build: 2020-Sep-04
- Platform: amd64
- Version: 3.3.1
- Fixed in version: 3.3.1
- Fixed in revision: 46973 (#a628c1c3)