> On Apr 6, 2021, at 11:34 PM, Sven Barth <pascaldra...@googlemail.com> wrote:
> 
> In the second case the compiler will have the non-generic Test(String) due to 
> the implicit operator as well as Test<LongInt>(LongInt) due to the implicit 
> specialization. Here it will pick the generic one, because a call without a 
> type conversion is considered better.

I finally get what you're saying and get the correct results now after moving 
my check inside the if/then block. I didn't realize that the operator overload 
was causing a type conversion that the overloading system knew about. So the 
non-generic still wins unless the type conversion happened due to the operator 
overload and then the generic wins.

        Writeln(Test('Hello World'));                   // Test(String)
        Writeln(Test(42));                                      // Test<String>
        Writeln(Test(String(42)));                      // Test(String)

As for $H+ do we really want string literals likes 'ABC' to change? I wouldn't 
think so. Here's my string literal type symbol conversion in 
create_unamed_typesym I'm using now:

              case tstringdef(def).stringtype of
                st_shortstring:
                  newtype:=search_system_type('SHORTSTRING');
                st_longstring,
                st_ansistring:
                  newtype:=search_system_type('ANSISTRING');
                st_widestring:
                  newtype:=search_system_type('WIDESTRING');
                st_unicodestring:
                  newtype:=search_system_type('UNICODESTRING');
              end;

'Hello World' is parsed as st_shortstring so we use System.ShortString for 
specialization. Given that I don't think I need to do anything with $H+.

Regards,
        Ryan Joseph

_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply via email to