Property expressions: Cannot assign "Integer" to "TEnum"
Issue #117
invalid
Is this a bug in DWScript?
Script:
unit Test;
type TIntegerField = class
property Name: String;
property Value: Integer;
end;
type TEnum = enum (Blub1, Blub2, Blub3);
type TFoo = class
property EnumField: TIntegerField;
property EnumFieldValue: TEnum read (EnumField.Value) write (EnumField.Value);
constructor Create;
begin
EnumField := new TIntegerField;
end;
end;
var Foo := new TFoo;
Foo.EnumField.Name := 'EnumName';
Foo.EnumField.Value := TEnum.Blub2;
PrintLn(Foo.EnumField.Name);
PrintLn(Foo.EnumField.Value);
PrintLn(Foo.EnumFieldValue);
Error:
Syntax Error: Incompatible types: Cannot assign "Integer" to "TEnum" [line: 12, column: 49]
Comments (2)
-
-
repo owner - changed status to invalid
Yes, Christian is right, this is by design (and same as in Delphi).
To convert between an integer and an enum, an explicit cast is required.
- Log in to comment
I don't think it's a bug in DWScript, because EnumField is of type TIntegerField and its property Value is an Integer. This integer type is different to the EnumFieldValue property type (TEnum).
I haven't tried this, but eventually you can cast it to TEnum like:
I'm not sure if this makes sense (in terms of legibility of the code), but eventually it compiles.