Hi together!

I'm currently wrapping V4L2 in an object oriented way and thought that I could use operator overloading to convert flag ordinals to Pascal sets. My operator compiled without problems, but when I tried to use it I got a type error.

So I reduced my problem to a single test unit:

==== begin ====

program opoverload;

{$mode objfpc}

type
  TTest = (
    test1,
    test2,
    test3
  );
  TTests = set of TTest;

operator := (aRight: LongWord) aLeft: TTests;
begin
  Result := [];
  if (aRight >= 0) and (aRight < 21) then
    Include(Result, test1);
  if (aRight >= 21) and (aRight <= 42) then
    Include(Result, test2);
  if (aRight >= 0) and (aRight <= 42) then
    Include(Result, test3);
end;

var
  i: LongWord;
  t: TTests;
begin
  i := 21;
//  t := i;
end.

==== end ====

Compiling it as is succeeds without problems, but enabling the commented assignment to "t" results in the following output:

====
> fpc opoverload.pasfpc opoverload.pas
Free Pascal Compiler version 2.4.0 [2010/01/01] for i386
Copyright (c) 1993-2009 by Florian Klaempfl
Target OS: Linux for i386
Compiling opoverload.pas
opoverload.pas(29,8) Error: Incompatible types: got "LongWord" expected "TTests"
opoverload.pas(31) Fatal: There were 1 errors compiling module, stopping
Fatal: Compilation aborted
Error: /home/sven/.bin/ppc386 returned an error exitcode (normal if you did not specify a source file to be compiled)
====

Is this a bug (I'm using 2.4.0, but I've tested it with a 2.5.1 from end of August as well)? Or is it not possible to use such an overload (which would be a pity...)?

Regards,
Sven
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to