Recent

Author Topic: [SOLVED] Illegal type conversion since one of last commit fpc 3.1.1.  (Read 1238 times)

Fred vS

  • Hero Member
  • *****
  • Posts: 3158
    • StrumPract is the musicians best friend
Hello.

This code is working good with fpc 3.2.2 and 3.2.3:

Code: Pascal  [Select][+][-]
  1. ...
  2. type
  3.  enumty = (sc_one, sc_two, sc_three);
  4.  strenumty = array[enumty] of string;
  5.  stringarty = array of string;
  6.  
  7. var
  8.  astrenumty : strenumty;
  9.  astringarty : stringarty;  
  10.  
  11. ...
  12.  
  13. astringarty := stringarty(astrenumty); // here
  14.  

But since one of the last commit of fpc 3.3.1, I get this error:

Quote
Error: Illegal type conversion: "strenumty" to "stringarty"

Fre;D
« Last Edit: May 27, 2022, 05:10:00 pm by Fred vS »
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Illegal type conversion since one of last commit fpc 3.1.1.
« Reply #1 on: May 27, 2022, 12:13:46 pm »
If the direct typecast is no longer allowed, then you have to do it by hand.
Code: Pascal  [Select][+][-]
  1. var
  2.  astrenumty : strenumty; astringarty : stringarty;
  3.  en: enumty;
  4.  
  5. ...
  6.    SetLength(astringarty, Length(astrenumty));
  7.   for en := Low(astrenumty) to High(astrenumty) do
  8.     astringarty[Ord(en)] := astrenumty[en];

Fred vS

  • Hero Member
  • *****
  • Posts: 3158
    • StrumPract is the musicians best friend
Re: Illegal type conversion since one of last commit fpc 3.1.1.
« Reply #2 on: May 27, 2022, 12:31:16 pm »
If the direct typecast is no longer allowed, then you have to do it by hand.
Code: Pascal  [Select][+][-]
  1. var
  2.  astrenumty : strenumty; astringarty : stringarty;
  3.  en: enumty;
  4.  
  5. ...
  6.    SetLength(astringarty, Length(astrenumty));
  7.   for en := Low(astrenumty) to High(astrenumty) do
  8.     astringarty[Ord(en)] := astrenumty[en];

Hello howardpc and thanks for answer.

If the direct typecast is no longer allowed, then it is very sad and it breaks lot of code that worked for age.
Is it a reason for that removed feature ( or is it a bug that hopefully will be fixed ) ?

Thanks.

Fre;D
« Last Edit: May 27, 2022, 12:59:48 pm by Fred vS »
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
Re: Illegal type conversion since one of last commit fpc 3.1.1.
« Reply #3 on: May 27, 2022, 03:27:29 pm »
But since one of the last commit of fpc 3.3.1, I get this error:

Quote
Error: Illegal type conversion: "strenumty" to "stringarty"

Might be this one.

Fred vS

  • Hero Member
  • *****
  • Posts: 3158
    • StrumPract is the musicians best friend
Re: Illegal type conversion since one of last commit fpc 3.1.1.
« Reply #4 on: May 27, 2022, 03:38:15 pm »
But since one of the last commit of fpc 3.3.1, I get this error:

Quote
Error: Illegal type conversion: "strenumty" to "stringarty"

Might be this one.

Hello PascalDragon and thanks for help.

Quote
or add {$modeswitch arraytodynarray}

Yep, this easy way seems to work, compilation is ok with it.
OK, I understand the reason why "automatic conversion" could make problems.

But I will first use {$modeswitch arraytodynarray} and one day convert all the code with the howardpc way.

Thanks.

Fre;D

I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

Thaddy

  • Hero Member
  • *****
  • Posts: 14205
  • Probably until I exterminate Putin.
Re: Illegal type conversion since one of last commit fpc 3.1.1.
« Reply #5 on: May 27, 2022, 04:50:23 pm »
https://wiki.freepascal.org/User_Changes_Trunk#Language_Changes under implementation changes.
In your case the modeswitch will work.
« Last Edit: May 27, 2022, 04:53:16 pm by Thaddy »
Specialize a type, not a var.

Fred vS

  • Hero Member
  • *****
  • Posts: 3158
    • StrumPract is the musicians best friend
Re: Illegal type conversion since one of last commit fpc 3.1.1.
« Reply #6 on: May 27, 2022, 05:08:11 pm »
https://wiki.freepascal.org/User_Changes_Trunk#Language_Changes under implementation changes.
In your case the modeswitch will work.

Hello Thaddy.

After deep test, I confirm that using switch {$modeswitch arraytodynarray} makes the unit compile + work like before.

Fre;D
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

Thaddy

  • Hero Member
  • *****
  • Posts: 14205
  • Probably until I exterminate Putin.
Note modeswitches are unit level, so mark your units that need it as e.g. deprecated 'newer units should not use this modeswitch';. (Or must be very clean with this in mind)
Specialize a type, not a var.

 

TinyPortal © 2005-2018