Procházet zdrojové kódy

* fixed overload choosing algorithm so it's Delphi-compatible +
tests (and test generator) (also fixes mantis 6641)

git-svn-id: trunk@5732 -

Jonas Maebe před 18 roky
rodič
revize
47ff7b62e7
100 změnil soubory, kde provedl 4355 přidání a 12 odebrání
  1. 174 0
      .gitattributes
  2. 187 7
      compiler/htypechk.pas
  3. 4 1
      compiler/ncal.pas
  4. 19 0
      compiler/symconst.pas
  5. 3 3
      tests/Makefile
  6. 1 1
      tests/Makefile.fpc
  7. 43 0
      tests/test/cg/variants/tvarol1.pp
  8. 42 0
      tests/test/cg/variants/tvarol10.pp
  9. 42 0
      tests/test/cg/variants/tvarol100.pp
  10. 42 0
      tests/test/cg/variants/tvarol101.pp
  11. 42 0
      tests/test/cg/variants/tvarol102.pp
  12. 43 0
      tests/test/cg/variants/tvarol103.pp
  13. 42 0
      tests/test/cg/variants/tvarol104.pp
  14. 42 0
      tests/test/cg/variants/tvarol105.pp
  15. 42 0
      tests/test/cg/variants/tvarol106.pp
  16. 42 0
      tests/test/cg/variants/tvarol107.pp
  17. 42 0
      tests/test/cg/variants/tvarol108.pp
  18. 42 0
      tests/test/cg/variants/tvarol109.pp
  19. 42 0
      tests/test/cg/variants/tvarol11.pp
  20. 42 0
      tests/test/cg/variants/tvarol110.pp
  21. 42 0
      tests/test/cg/variants/tvarol111.pp
  22. 42 0
      tests/test/cg/variants/tvarol112.pp
  23. 42 0
      tests/test/cg/variants/tvarol113.pp
  24. 43 0
      tests/test/cg/variants/tvarol114.pp
  25. 42 0
      tests/test/cg/variants/tvarol115.pp
  26. 42 0
      tests/test/cg/variants/tvarol116.pp
  27. 43 0
      tests/test/cg/variants/tvarol117.pp
  28. 42 0
      tests/test/cg/variants/tvarol118.pp
  29. 42 0
      tests/test/cg/variants/tvarol119.pp
  30. 43 0
      tests/test/cg/variants/tvarol12.pp
  31. 42 0
      tests/test/cg/variants/tvarol120.pp
  32. 42 0
      tests/test/cg/variants/tvarol121.pp
  33. 42 0
      tests/test/cg/variants/tvarol122.pp
  34. 42 0
      tests/test/cg/variants/tvarol123.pp
  35. 43 0
      tests/test/cg/variants/tvarol124.pp
  36. 42 0
      tests/test/cg/variants/tvarol125.pp
  37. 42 0
      tests/test/cg/variants/tvarol126.pp
  38. 42 0
      tests/test/cg/variants/tvarol127.pp
  39. 42 0
      tests/test/cg/variants/tvarol128.pp
  40. 42 0
      tests/test/cg/variants/tvarol129.pp
  41. 43 0
      tests/test/cg/variants/tvarol13.pp
  42. 42 0
      tests/test/cg/variants/tvarol130.pp
  43. 42 0
      tests/test/cg/variants/tvarol131.pp
  44. 42 0
      tests/test/cg/variants/tvarol132.pp
  45. 43 0
      tests/test/cg/variants/tvarol133.pp
  46. 42 0
      tests/test/cg/variants/tvarol134.pp
  47. 42 0
      tests/test/cg/variants/tvarol135.pp
  48. 42 0
      tests/test/cg/variants/tvarol136.pp
  49. 42 0
      tests/test/cg/variants/tvarol137.pp
  50. 42 0
      tests/test/cg/variants/tvarol138.pp
  51. 42 0
      tests/test/cg/variants/tvarol139.pp
  52. 43 0
      tests/test/cg/variants/tvarol14.pp
  53. 42 0
      tests/test/cg/variants/tvarol140.pp
  54. 42 0
      tests/test/cg/variants/tvarol141.pp
  55. 42 0
      tests/test/cg/variants/tvarol142.pp
  56. 42 0
      tests/test/cg/variants/tvarol143.pp
  57. 42 0
      tests/test/cg/variants/tvarol144.pp
  58. 42 0
      tests/test/cg/variants/tvarol145.pp
  59. 42 0
      tests/test/cg/variants/tvarol146.pp
  60. 42 0
      tests/test/cg/variants/tvarol147.pp
  61. 42 0
      tests/test/cg/variants/tvarol148.pp
  62. 42 0
      tests/test/cg/variants/tvarol149.pp
  63. 42 0
      tests/test/cg/variants/tvarol15.pp
  64. 42 0
      tests/test/cg/variants/tvarol150.pp
  65. 42 0
      tests/test/cg/variants/tvarol151.pp
  66. 42 0
      tests/test/cg/variants/tvarol152.pp
  67. 42 0
      tests/test/cg/variants/tvarol153.pp
  68. 43 0
      tests/test/cg/variants/tvarol154.pp
  69. 42 0
      tests/test/cg/variants/tvarol155.pp
  70. 42 0
      tests/test/cg/variants/tvarol156.pp
  71. 46 0
      tests/test/cg/variants/tvarol157.pp
  72. 42 0
      tests/test/cg/variants/tvarol158.pp
  73. 43 0
      tests/test/cg/variants/tvarol159.pp
  74. 43 0
      tests/test/cg/variants/tvarol16.pp
  75. 42 0
      tests/test/cg/variants/tvarol160.pp
  76. 42 0
      tests/test/cg/variants/tvarol161.pp
  77. 42 0
      tests/test/cg/variants/tvarol162.pp
  78. 43 0
      tests/test/cg/variants/tvarol163.pp
  79. 42 0
      tests/test/cg/variants/tvarol164.pp
  80. 42 0
      tests/test/cg/variants/tvarol165.pp
  81. 42 0
      tests/test/cg/variants/tvarol166.pp
  82. 42 0
      tests/test/cg/variants/tvarol167.pp
  83. 43 0
      tests/test/cg/variants/tvarol168.pp
  84. 42 0
      tests/test/cg/variants/tvarol169.pp
  85. 42 0
      tests/test/cg/variants/tvarol17.pp
  86. 42 0
      tests/test/cg/variants/tvarol170.pp
  87. 42 0
      tests/test/cg/variants/tvarol171.pp
  88. 42 0
      tests/test/cg/variants/tvarol18.pp
  89. 42 0
      tests/test/cg/variants/tvarol19.pp
  90. 42 0
      tests/test/cg/variants/tvarol2.pp
  91. 43 0
      tests/test/cg/variants/tvarol20.pp
  92. 42 0
      tests/test/cg/variants/tvarol21.pp
  93. 42 0
      tests/test/cg/variants/tvarol22.pp
  94. 42 0
      tests/test/cg/variants/tvarol23.pp
  95. 42 0
      tests/test/cg/variants/tvarol24.pp
  96. 42 0
      tests/test/cg/variants/tvarol25.pp
  97. 42 0
      tests/test/cg/variants/tvarol26.pp
  98. 42 0
      tests/test/cg/variants/tvarol27.pp
  99. 42 0
      tests/test/cg/variants/tvarol28.pp
  100. 42 0
      tests/test/cg/variants/tvarol29.pp

+ 174 - 0
.gitattributes

@@ -6474,6 +6474,177 @@ tests/test/cg/ttryfin3.pp svneol=native#text/plain
 tests/test/cg/ttryfin4.pp svneol=native#text/plain
 tests/test/cg/tvec.pp svneol=native#text/plain
 tests/test/cg/uprintf3.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol1.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol10.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol100.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol101.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol102.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol103.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol104.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol105.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol106.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol107.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol108.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol109.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol11.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol110.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol111.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol112.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol113.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol114.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol115.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol116.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol117.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol118.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol119.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol12.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol120.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol121.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol122.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol123.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol124.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol125.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol126.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol127.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol128.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol129.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol13.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol130.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol131.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol132.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol133.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol134.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol135.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol136.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol137.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol138.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol139.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol14.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol140.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol141.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol142.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol143.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol144.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol145.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol146.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol147.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol148.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol149.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol15.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol150.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol151.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol152.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol153.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol154.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol155.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol156.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol157.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol158.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol159.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol16.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol160.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol161.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol162.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol163.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol164.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol165.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol166.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol167.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol168.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol169.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol17.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol170.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol171.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol18.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol19.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol2.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol20.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol21.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol22.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol23.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol24.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol25.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol26.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol27.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol28.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol29.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol3.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol30.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol31.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol32.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol33.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol34.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol35.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol36.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol37.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol38.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol39.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol4.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol40.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol41.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol42.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol43.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol44.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol45.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol46.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol47.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol48.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol49.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol5.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol50.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol51.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol52.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol53.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol54.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol55.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol56.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol57.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol58.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol59.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol6.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol60.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol61.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol62.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol63.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol64.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol65.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol66.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol67.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol68.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol69.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol7.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol70.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol71.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol72.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol73.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol74.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol75.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol76.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol77.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol78.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol79.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol8.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol80.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol81.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol82.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol83.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol84.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol85.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol86.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol87.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol88.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol89.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol9.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol90.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol91.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol92.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol93.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol94.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol95.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol96.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol97.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol98.pp svneol=native#text/plain
+tests/test/cg/variants/tvarol99.pp svneol=native#text/plain
 tests/test/dumpclass.pp svneol=native#text/plain
 tests/test/dumpmethods.pp svneol=native#text/plain
 tests/test/opt/README -text
@@ -6815,6 +6986,8 @@ tests/utils/testsuite/testsuite.pp svneol=native#text/plain
 tests/utils/testsuite/testsuite.sql svneol=native#text/plain
 tests/utils/testsuite/utests.pp svneol=native#text/plain
 tests/utils/testu.pp svneol=native#text/plain
+tests/utils/variants/genvartests.pp svneol=native#text/plain
+tests/utils/variants/processtests.sh svneol=native#text/plain
 tests/webtbf/tw0744.pp svneol=native#text/plain
 tests/webtbf/tw0769b.pp svneol=native#text/plain
 tests/webtbf/tw0769c.pp svneol=native#text/plain
@@ -7766,6 +7939,7 @@ tests/webtbs/tw6203.pp svneol=native#text/plain
 tests/webtbs/tw6435.pp svneol=native#text/plain
 tests/webtbs/tw6491.pp svneol=native#text/plain
 tests/webtbs/tw6624.pp svneol=native#text/plain
+tests/webtbs/tw6641.pp svneol=native#text/plain
 tests/webtbs/tw6684.pp svneol=native#text/plain
 tests/webtbs/tw6686.pp svneol=native#text/plain
 tests/webtbs/tw6700.pp svneol=native#text/plain

+ 187 - 7
compiler/htypechk.pas

@@ -73,7 +73,7 @@ interface
         procedure dump_info(lvl:longint);
 {$endif EXTDEBUG}
         procedure get_information;
-        function  choose_best(var bestpd:tabstractprocdef):integer;
+        function  choose_best(var bestpd:tabstractprocdef; singlevariant: boolean):integer;
         procedure find_wrong_para;
         property  Count:integer read FProcCnt;
         property  VisibleCount:integer read FProcVisibleCnt;
@@ -451,7 +451,7 @@ implementation
         { Display info when multiple candidates are found }
         candidates.dump_info(V_Debug);
 {$endif EXTDEBUG}
-        cand_cnt:=candidates.choose_best(operpd);
+        cand_cnt:=candidates.choose_best(operpd,false);
 
         { exit when no overloads are found }
         if cand_cnt=0 then
@@ -597,7 +597,7 @@ implementation
         { Display info when multiple candidates are found }
         candidates.dump_info(V_Debug);
 {$endif EXTDEBUG}
-        cand_cnt:=candidates.choose_best(operpd);
+        cand_cnt:=candidates.choose_best(operpd,false);
 
         { exit when no overloads are found }
         if cand_cnt=0 then
@@ -2133,6 +2133,183 @@ implementation
       end;
 
 
+    function get_variantequaltype(def: tdef): tvariantequaltype;
+      const
+        variantorddef_cl: array[tordtype] of tvariantequaltype =
+          (tve_incompatible,tve_byte,tve_word,tve_cardinal,tve_chari64,
+           tve_shortint,tve_smallint,tve_longint,tve_chari64,
+           tve_boolformal,tve_boolformal,tve_boolformal,tve_boolformal,
+           tve_chari64,tve_chari64,tve_dblcurrency);
+{$warning fixme for 128 bit floats }
+        variantfloatdef_cl: array[tfloattype] of tvariantequaltype =
+          (tve_single,tve_dblcurrency,tve_extended,
+           tve_dblcurrency,tve_dblcurrency,tve_extended);
+        variantstringdef_cl: array[tstringtype] of tvariantequaltype =
+          (tve_sstring,tve_astring,tve_astring,tve_wstring);
+      begin
+        result:=tve_incompatible;
+        case def.typ of
+          orddef:
+            begin
+              result:=variantorddef_cl[torddef(def).ordtype];
+            end;
+          floatdef:
+            begin
+              result:=variantfloatdef_cl[tfloatdef(def).floattype];
+            end;
+          stringdef:
+            begin
+              result:=variantstringdef_cl[tstringdef(def).stringtype];
+            end;
+          formaldef:
+            begin
+              result:=tve_boolformal;
+            end;
+          else
+            internalerror(2006122804);
+        end
+      end;
+
+
+{ Delphi precedence rules extracted from test programs. Only valid if passing
+  a variant parameter to overloaded procedures expecting exactly one parameter.
+
+  single > (char, currency, int64, shortstring, ansistring, widestring, extended, double)
+  double/currency > (char, int64, shortstring, ansistring, widestring, extended)
+  extended > (char, int64, shortstring, ansistring, widestring)
+  longint/cardinal > (int64, shortstring, ansistring, widestring, extended, double, single, char, currency)
+  smallint > (longint, int64, shortstring, ansistring, widestring, extended, double single, char, currency);
+  word > (longint, cardinal, int64, shortstring, ansistring, widestring, extended, double single, char, currency);
+  shortint > (longint, smallint, int64, shortstring, ansistring, widestring, extended, double, single, char, currency)
+  byte > (longint, cardinal, word, smallint, int64, shortstring, ansistring, widestring, extended, double, single, char, currency);
+  boolean/formal > (char, int64, shortstring, ansistring, widestring)
+  shortstring > (char, int64, ansistring, widestring)
+  ansistring > (char, int64, widestring)
+  widestring > (char, int64)
+
+  Relations not mentioned mean that they conflict: no decision possible }
+
+    function is_better_candidate_single_variant(currpd,bestpd:pcandidate):integer;
+
+      function calculate_relation(const currvcl, bestvcl, testvcl:
+          tvariantequaltype; const conflictvcls: tvariantequaltypes):integer;
+        begin
+          { if (bestvcl=conflictvcl) or
+               (currvcl=conflictvcl) then
+              result:=0
+            else if (bestvcl=testvcl) then
+              result:=-1
+            else result:=1 }
+          result:=1-2*ord(bestvcl=testvcl)+
+                  ord(currvcl in conflictvcls)-ord(bestvcl in conflictvcls);
+        end;
+
+      var
+        paraidx,
+        res: integer;
+        currpara, bestpara: tparavarsym;
+        currvcl, bestvcl: tvariantequaltype;
+      begin
+        {
+          Return values:
+            > 0 when currpd is better than bestpd
+            < 0 when bestpd is better than currpd
+            = 0 when both are equal
+        }
+        if (currpd^.firstparaidx<>bestpd^.firstparaidx) then
+          internalerror(2006122801);
+         paraidx:=currpd^.firstparaidx;
+         while (paraidx>=0) and (vo_is_hidden_para in tparavarsym(currpd^.data.paras[paraidx]).varoptions) do
+           if (vo_is_hidden_para in tparavarsym(bestpd^.data.paras[paraidx]).varoptions) then
+             dec(paraidx)
+           else
+             internalerror(2006122802);
+        if (vo_is_hidden_para in tparavarsym(currpd^.data.paras[paraidx]).varoptions) then
+          internalerror(2006122803);
+        currpara:=tparavarsym(currpd^.data.paras[paraidx]);
+        bestpara:=tparavarsym(bestpd^.data.paras[paraidx]);
+        currvcl:=get_variantequaltype(currpara.vardef);
+        bestvcl:=get_variantequaltype(bestpara.vardef);
+
+        { sanity check }
+        result:=-5;
+
+        { if both are the same, there is a conflict }
+        if (currvcl=bestvcl) then
+          result:=0
+        { boolean and formal are better than chari64str, but conflict with }
+        { everything else                                                  }
+        else if (currvcl=tve_boolformal) or
+                (bestvcl=tve_boolformal) then
+          if (currvcl=tve_boolformal) then
+            result:=ord(bestvcl in [tve_chari64,tve_sstring,tve_astring,tve_wstring])
+          else
+            result:=-ord(currvcl in [tve_chari64,tve_sstring,tve_astring,tve_wstring])
+        { byte is better than everything else (we assume both aren't byte, }
+        { since there's only one parameter and that one can't be the same) }
+        else if (currvcl=tve_byte) or
+                (bestvcl=tve_byte) then
+          result:=calculate_relation(currvcl,bestvcl,tve_byte,[tve_shortint])
+        { shortint conflicts with word and cardinal, but is better than    }
+        { everything else but byte (which has already been handled)        }
+        else if (currvcl=tve_shortint) or
+                (bestvcl=tve_shortint) then
+          result:=calculate_relation(currvcl,bestvcl,tve_shortint,[tve_word, tve_cardinal])
+        { word conflicts with smallint, but is better than everything else }
+        { but shortint and byte (which has already been handled)           }
+        else if (currvcl=tve_word) or
+                (bestvcl=tve_word) then
+          result:=calculate_relation(currvcl,bestvcl,tve_word,[tve_smallint])
+        { smallint conflicts with cardinal, but is better than everything  }
+        { which has not yet been tested                                    }
+        else if (currvcl=tve_smallint) or
+                (bestvcl=tve_smallint) then
+          result:=calculate_relation(currvcl,bestvcl,tve_smallint,[tve_cardinal])
+        { cardinal conflicts with each longint and is better than everything }
+        { which has not yet been tested                                      }
+        else if (currvcl = tve_cardinal) or
+                (bestvcl=tve_cardinal) then
+          result:=calculate_relation(currvcl,bestvcl,tve_cardinal,[tve_longint])
+        { longint is better than everything which has not yet been tested }
+        else if (currvcl=tve_longint) or
+                (bestvcl=tve_longint) then
+          { if bestvcl=tve_longint then
+              result:=-1
+            else
+              result:=1 }
+          result:=1-2*ord(bestvcl=tve_longint)
+        { single is better than everything left }
+        else if (currvcl=tve_single) or
+                (bestvcl=tve_single) then
+          result:=1-2*ord(bestvcl=tve_single)
+        { double/comp/currency are better than everything left, and conflict }
+        { with each other (but that's already tested)                        }
+        else if (currvcl=tve_dblcurrency) or
+                (bestvcl=tve_dblcurrency) then
+          result:=1-2*ord(bestvcl=tve_dblcurrency)
+        { extended is better than everything left }
+        else if (currvcl=tve_extended) or
+                (bestvcl=tve_extended) then
+          result:=1-2*ord(bestvcl=tve_extended)
+        { shortstring is better than everything left }
+        else if (currvcl=tve_sstring) or
+                (bestvcl=tve_sstring) then
+          result:=1-2*ord(bestvcl=tve_sstring)
+        { ansistring is better than everything left }
+        else if (currvcl=tve_astring) or
+                (bestvcl=tve_astring) then
+          result:=1-2*ord(bestvcl=tve_astring)
+        { widestring is better than everything left }
+        else if (currvcl=tve_wstring) or
+                (bestvcl=tve_wstring) then
+          result:=1-2*ord(bestvcl=tve_wstring);
+
+        { all possibilities should have been checked now }
+        if (result=-5) then
+          internalerror(2006122805);
+      end;
+
+
     function is_better_candidate(currpd,bestpd:pcandidate):integer;
       var
         res : integer;
@@ -2208,12 +2385,12 @@ implementation
       end;
 
 
-    function tcallcandidates.choose_best(var bestpd:tabstractprocdef):integer;
+    function tcallcandidates.choose_best(var bestpd:tabstractprocdef; singlevariant: boolean):integer;
       var
         besthpstart,
-        hp       : pcandidate;
+        hp            : pcandidate;
         cntpd,
-        res      : integer;
+        res           : integer;
       begin
         {
           Returns the number of candidates left and the
@@ -2232,7 +2409,10 @@ implementation
            hp:=FProcs^.next;
            while assigned(hp) do
             begin
-              res:=is_better_candidate(hp,besthpstart);
+              if not singlevariant then
+                res:=is_better_candidate(hp,besthpstart)
+              else
+                res:=is_better_candidate_single_variant(hp,besthpstart);
               if (res>0) then
                begin
                  { hp is better, flag all procs to be incompatible }

+ 4 - 1
compiler/ncal.pas

@@ -1913,7 +1913,10 @@ implementation
 
                    { Choose the best candidate and count the number of
                      candidates left }
-                   cand_cnt:=candidates.choose_best(procdefinition);
+                   cand_cnt:=candidates.choose_best(procdefinition,
+                     assigned(left) and
+                     not assigned(tcallparanode(left).right) and
+                     (tcallparanode(left).left.resultdef.typ=variantdef));
 
                    { All parameters are checked, check if there are any
                      procedures left }

+ 19 - 0
compiler/symconst.pas

@@ -426,6 +426,25 @@ type
     te_exact
   );
 
+  tvariantequaltype = (
+    tve_incompatible,
+    tve_chari64,
+    tve_wstring,
+    tve_astring,
+    tve_sstring,
+    tve_boolformal,
+    tve_extended,
+    tve_dblcurrency,
+    tve_single,
+    tve_cardinal,
+    tve_longint,
+    tve_smallint,
+    tve_word,
+    tve_shortint,
+    tve_byte
+  );
+  tvariantequaltypes = set of tvariantequaltype;
+
   tdefdbgstatus = (
     dbg_state_unused,
     dbg_state_used,

+ 3 - 3
tests/Makefile

@@ -1,8 +1,8 @@
 #
-# Don't edit, this file is generated by FPCMake Version 2.0.0 [2006/10/31]
+# Don't edit, this file is generated by FPCMake Version 2.0.0 [2006/12/19]
 #
 default: allexectests
-MAKEFILETARGETS=i386-linux i386-go32v2 i386-win32 i386-os2 i386-freebsd i386-beos i386-netbsd i386-solaris i386-qnx i386-netware i386-openbsd i386-wdosx i386-darwin i386-emx i386-watcom i386-netwlibc i386-wince m68k-linux m68k-freebsd m68k-netbsd m68k-amiga m68k-atari m68k-openbsd m68k-palmos powerpc-linux powerpc-netbsd powerpc-amiga powerpc-macos powerpc-darwin powerpc-morphos sparc-linux sparc-netbsd sparc-solaris x86_64-linux x86_64-freebsd x86_64-win64 arm-linux arm-palmos arm-wince arm-gba powerpc64-linux
+MAKEFILETARGETS=i386-linux i386-go32v2 i386-win32 i386-os2 i386-freebsd i386-beos i386-netbsd i386-solaris i386-qnx i386-netware i386-openbsd i386-wdosx i386-darwin i386-emx i386-watcom i386-netwlibc i386-wince i386-embedded m68k-linux m68k-freebsd m68k-netbsd m68k-amiga m68k-atari m68k-openbsd m68k-palmos m68k-embedded powerpc-linux powerpc-netbsd powerpc-amiga powerpc-macos powerpc-darwin powerpc-morphos powerpc-embedded sparc-linux sparc-netbsd sparc-solaris sparc-embedded x86_64-linux x86_64-freebsd x86_64-win64 x86_64-embedded arm-linux arm-palmos arm-wince arm-gba arm-nds arm-embedded powerpc64-linux powerpc64-embedded
 BSDs = freebsd netbsd openbsd darwin
 UNIXs = linux $(BSDs) solaris qnx
 LIMIT83fs = go32v2 os2 emx watcom
@@ -1380,7 +1380,7 @@ endif
 ifndef LOG
 export LOG:=$(TEST_OUTPUTDIR)/log
 endif
-TESTSUBDIRS=cg cg/cdecl units/system units/dos units/crt units/objects units/strings units/sysutils units/math units/sharemem
+TESTSUBDIRS=cg cg/variants cg/cdecl units/system units/dos units/crt units/objects units/strings units/sysutils units/math units/sharemem
 TESTDIRS:=test $(addprefix test/,$(TESTSUBDIRS))
 .PHONY: utils units copyfiles testprep
 utils:

+ 1 - 1
tests/Makefile.fpc

@@ -107,7 +107,7 @@ endif
 
 
 # Subdirs available in the test subdir
-TESTSUBDIRS=cg cg/cdecl units/system units/dos units/crt units/objects units/strings units/sysutils units/math units/sharemem
+TESTSUBDIRS=cg cg/variants cg/cdecl units/system units/dos units/crt units/objects units/strings units/sysutils units/math units/sharemem
 
 # All full dirnames in the test/ dir including the subdir self
 TESTDIRS:=test $(addprefix test/,$(TESTSUBDIRS))

+ 43 - 0
tests/test/cg/variants/tvarol1.pp

@@ -0,0 +1,43 @@
+{ %fail }
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = double;
+{$endif FPC_COMP_IS_INT64}
+procedure test(var a); overload;
+  begin
+    writeln('formal called instead of comp');
+    writeln('XXX')
+  end;
+
+procedure test(a: comp); overload;
+  begin
+    writeln('comp called instead of formal');
+    writeln('YYY')
+  end;
+
+var
+  v: variant;
+  x: longint;
+  y: comp;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      writeln('QQQ');
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      writeln('VVV');
+  end;
+end.

+ 42 - 0
tests/test/cg/variants/tvarol10.pp

@@ -0,0 +1,42 @@
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = double;
+{$endif FPC_COMP_IS_INT64}
+procedure test(var a); overload;
+  begin
+    writeln('formal called instead of shortstring');
+    writeln('XXX')
+  end;
+
+procedure test(a: shortstring); overload;
+  begin
+    writeln('shortstring called instead of formal');
+    halt(1)
+  end;
+
+var
+  v: variant;
+  x: longint;
+  y: shortstring;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+end.

+ 42 - 0
tests/test/cg/variants/tvarol100.pp

@@ -0,0 +1,42 @@
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = currency;
+{$endif FPC_COMP_IS_INT64}
+procedure test(a: word); overload;
+  begin
+    writeln('word called instead of double');
+    writeln('XXX')
+  end;
+
+procedure test(a: double); overload;
+  begin
+    writeln('double called instead of word');
+    halt(1)
+  end;
+
+var
+  v: variant;
+  x: word;
+  y: double;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+end.

+ 42 - 0
tests/test/cg/variants/tvarol101.pp

@@ -0,0 +1,42 @@
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = currency;
+{$endif FPC_COMP_IS_INT64}
+procedure test(a: word); overload;
+  begin
+    writeln('word called instead of extended');
+    writeln('XXX')
+  end;
+
+procedure test(a: extended); overload;
+  begin
+    writeln('extended called instead of word');
+    halt(1)
+  end;
+
+var
+  v: variant;
+  x: word;
+  y: extended;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+end.

+ 42 - 0
tests/test/cg/variants/tvarol102.pp

@@ -0,0 +1,42 @@
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = double;
+{$endif FPC_COMP_IS_INT64}
+procedure test(a: word); overload;
+  begin
+    writeln('word called instead of char');
+    writeln('XXX')
+  end;
+
+procedure test(a: char); overload;
+  begin
+    writeln('char called instead of word');
+    halt(1)
+  end;
+
+var
+  v: variant;
+  x: word;
+  y: char;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      writeln('VVV');
+  end;
+end.

+ 43 - 0
tests/test/cg/variants/tvarol103.pp

@@ -0,0 +1,43 @@
+{ %fail }
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = double;
+{$endif FPC_COMP_IS_INT64}
+procedure test(a: word); overload;
+  begin
+    writeln('word called instead of boolean');
+    writeln('XXX')
+  end;
+
+procedure test(a: boolean); overload;
+  begin
+    writeln('boolean called instead of word');
+    writeln('YYY')
+  end;
+
+var
+  v: variant;
+  x: word;
+  y: boolean;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      writeln('QQQ');
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      writeln('VVV');
+  end;
+end.

+ 42 - 0
tests/test/cg/variants/tvarol104.pp

@@ -0,0 +1,42 @@
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = double;
+{$endif FPC_COMP_IS_INT64}
+procedure test(a: word); overload;
+  begin
+    writeln('word called instead of widestring');
+    writeln('XXX')
+  end;
+
+procedure test(a: widestring); overload;
+  begin
+    writeln('widestring called instead of word');
+    halt(1)
+  end;
+
+var
+  v: variant;
+  x: word;
+  y: widestring;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      writeln('VVV');
+  end;
+end.

+ 42 - 0
tests/test/cg/variants/tvarol105.pp

@@ -0,0 +1,42 @@
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = double;
+{$endif FPC_COMP_IS_INT64}
+procedure test(a: word); overload;
+  begin
+    writeln('word called instead of widechar');
+    writeln('XXX')
+  end;
+
+procedure test(a: widechar); overload;
+  begin
+    writeln('widechar called instead of word');
+    halt(1)
+  end;
+
+var
+  v: variant;
+  x: word;
+  y: widechar;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+end.

+ 42 - 0
tests/test/cg/variants/tvarol106.pp

@@ -0,0 +1,42 @@
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = double;
+{$endif FPC_COMP_IS_INT64}
+procedure test(a: smallint); overload;
+  begin
+    writeln('smallint called instead of byte');
+    halt(1)
+  end;
+
+procedure test(a: byte); overload;
+  begin
+    writeln('byte called instead of smallint');
+    writeln('YYY')
+  end;
+
+var
+  v: variant;
+  x: smallint;
+  y: byte;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+end.

+ 42 - 0
tests/test/cg/variants/tvarol107.pp

@@ -0,0 +1,42 @@
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = double;
+{$endif FPC_COMP_IS_INT64}
+procedure test(a: smallint); overload;
+  begin
+    writeln('smallint called instead of shortint');
+    halt(1)
+  end;
+
+procedure test(a: shortint); overload;
+  begin
+    writeln('shortint called instead of smallint');
+    writeln('YYY')
+  end;
+
+var
+  v: variant;
+  x: smallint;
+  y: shortint;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+end.

+ 42 - 0
tests/test/cg/variants/tvarol108.pp

@@ -0,0 +1,42 @@
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = double;
+{$endif FPC_COMP_IS_INT64}
+procedure test(a: smallint); overload;
+  begin
+    writeln('smallint called instead of shortstring');
+    writeln('XXX')
+  end;
+
+procedure test(a: shortstring); overload;
+  begin
+    writeln('shortstring called instead of smallint');
+    halt(1)
+  end;
+
+var
+  v: variant;
+  x: smallint;
+  y: shortstring;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      writeln('VVV');
+  end;
+end.

+ 42 - 0
tests/test/cg/variants/tvarol109.pp

@@ -0,0 +1,42 @@
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = double;
+{$endif FPC_COMP_IS_INT64}
+procedure test(a: smallint); overload;
+  begin
+    writeln('smallint called instead of ansistring');
+    writeln('XXX')
+  end;
+
+procedure test(a: ansistring); overload;
+  begin
+    writeln('ansistring called instead of smallint');
+    halt(1)
+  end;
+
+var
+  v: variant;
+  x: smallint;
+  y: ansistring;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      writeln('VVV');
+  end;
+end.

+ 42 - 0
tests/test/cg/variants/tvarol11.pp

@@ -0,0 +1,42 @@
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = double;
+{$endif FPC_COMP_IS_INT64}
+procedure test(var a); overload;
+  begin
+    writeln('formal called instead of ansistring');
+    writeln('XXX')
+  end;
+
+procedure test(a: ansistring); overload;
+  begin
+    writeln('ansistring called instead of formal');
+    halt(1)
+  end;
+
+var
+  v: variant;
+  x: longint;
+  y: ansistring;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+end.

+ 42 - 0
tests/test/cg/variants/tvarol110.pp

@@ -0,0 +1,42 @@
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = double;
+{$endif FPC_COMP_IS_INT64}
+procedure test(a: smallint); overload;
+  begin
+    writeln('smallint called instead of single');
+    writeln('XXX')
+  end;
+
+procedure test(a: single); overload;
+  begin
+    writeln('single called instead of smallint');
+    halt(1)
+  end;
+
+var
+  v: variant;
+  x: smallint;
+  y: single;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+end.

+ 42 - 0
tests/test/cg/variants/tvarol111.pp

@@ -0,0 +1,42 @@
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = currency;
+{$endif FPC_COMP_IS_INT64}
+procedure test(a: smallint); overload;
+  begin
+    writeln('smallint called instead of double');
+    writeln('XXX')
+  end;
+
+procedure test(a: double); overload;
+  begin
+    writeln('double called instead of smallint');
+    halt(1)
+  end;
+
+var
+  v: variant;
+  x: smallint;
+  y: double;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+end.

+ 42 - 0
tests/test/cg/variants/tvarol112.pp

@@ -0,0 +1,42 @@
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = currency;
+{$endif FPC_COMP_IS_INT64}
+procedure test(a: smallint); overload;
+  begin
+    writeln('smallint called instead of extended');
+    writeln('XXX')
+  end;
+
+procedure test(a: extended); overload;
+  begin
+    writeln('extended called instead of smallint');
+    halt(1)
+  end;
+
+var
+  v: variant;
+  x: smallint;
+  y: extended;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+end.

+ 42 - 0
tests/test/cg/variants/tvarol113.pp

@@ -0,0 +1,42 @@
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = double;
+{$endif FPC_COMP_IS_INT64}
+procedure test(a: smallint); overload;
+  begin
+    writeln('smallint called instead of char');
+    writeln('XXX')
+  end;
+
+procedure test(a: char); overload;
+  begin
+    writeln('char called instead of smallint');
+    halt(1)
+  end;
+
+var
+  v: variant;
+  x: smallint;
+  y: char;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      writeln('VVV');
+  end;
+end.

+ 43 - 0
tests/test/cg/variants/tvarol114.pp

@@ -0,0 +1,43 @@
+{ %fail }
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = double;
+{$endif FPC_COMP_IS_INT64}
+procedure test(a: smallint); overload;
+  begin
+    writeln('smallint called instead of boolean');
+    writeln('XXX')
+  end;
+
+procedure test(a: boolean); overload;
+  begin
+    writeln('boolean called instead of smallint');
+    writeln('YYY')
+  end;
+
+var
+  v: variant;
+  x: smallint;
+  y: boolean;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      writeln('QQQ');
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      writeln('VVV');
+  end;
+end.

+ 42 - 0
tests/test/cg/variants/tvarol115.pp

@@ -0,0 +1,42 @@
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = double;
+{$endif FPC_COMP_IS_INT64}
+procedure test(a: smallint); overload;
+  begin
+    writeln('smallint called instead of widestring');
+    writeln('XXX')
+  end;
+
+procedure test(a: widestring); overload;
+  begin
+    writeln('widestring called instead of smallint');
+    halt(1)
+  end;
+
+var
+  v: variant;
+  x: smallint;
+  y: widestring;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      writeln('VVV');
+  end;
+end.

+ 42 - 0
tests/test/cg/variants/tvarol116.pp

@@ -0,0 +1,42 @@
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = double;
+{$endif FPC_COMP_IS_INT64}
+procedure test(a: smallint); overload;
+  begin
+    writeln('smallint called instead of widechar');
+    writeln('XXX')
+  end;
+
+procedure test(a: widechar); overload;
+  begin
+    writeln('widechar called instead of smallint');
+    halt(1)
+  end;
+
+var
+  v: variant;
+  x: smallint;
+  y: widechar;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+end.

+ 43 - 0
tests/test/cg/variants/tvarol117.pp

@@ -0,0 +1,43 @@
+{ %fail }
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = double;
+{$endif FPC_COMP_IS_INT64}
+procedure test(a: byte); overload;
+  begin
+    writeln('byte called instead of shortint');
+    writeln('XXX')
+  end;
+
+procedure test(a: shortint); overload;
+  begin
+    writeln('shortint called instead of byte');
+    writeln('YYY')
+  end;
+
+var
+  v: variant;
+  x: byte;
+  y: shortint;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      writeln('QQQ');
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      writeln('VVV');
+  end;
+end.

+ 42 - 0
tests/test/cg/variants/tvarol118.pp

@@ -0,0 +1,42 @@
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = double;
+{$endif FPC_COMP_IS_INT64}
+procedure test(a: byte); overload;
+  begin
+    writeln('byte called instead of shortstring');
+    writeln('XXX')
+  end;
+
+procedure test(a: shortstring); overload;
+  begin
+    writeln('shortstring called instead of byte');
+    halt(1)
+  end;
+
+var
+  v: variant;
+  x: byte;
+  y: shortstring;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      writeln('VVV');
+  end;
+end.

+ 42 - 0
tests/test/cg/variants/tvarol119.pp

@@ -0,0 +1,42 @@
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = double;
+{$endif FPC_COMP_IS_INT64}
+procedure test(a: byte); overload;
+  begin
+    writeln('byte called instead of ansistring');
+    writeln('XXX')
+  end;
+
+procedure test(a: ansistring); overload;
+  begin
+    writeln('ansistring called instead of byte');
+    halt(1)
+  end;
+
+var
+  v: variant;
+  x: byte;
+  y: ansistring;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      writeln('VVV');
+  end;
+end.

+ 43 - 0
tests/test/cg/variants/tvarol12.pp

@@ -0,0 +1,43 @@
+{ %fail }
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = double;
+{$endif FPC_COMP_IS_INT64}
+procedure test(var a); overload;
+  begin
+    writeln('formal called instead of single');
+    writeln('XXX')
+  end;
+
+procedure test(a: single); overload;
+  begin
+    writeln('single called instead of formal');
+    writeln('YYY')
+  end;
+
+var
+  v: variant;
+  x: longint;
+  y: single;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      writeln('QQQ');
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      writeln('VVV');
+  end;
+end.

+ 42 - 0
tests/test/cg/variants/tvarol120.pp

@@ -0,0 +1,42 @@
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = double;
+{$endif FPC_COMP_IS_INT64}
+procedure test(a: byte); overload;
+  begin
+    writeln('byte called instead of single');
+    writeln('XXX')
+  end;
+
+procedure test(a: single); overload;
+  begin
+    writeln('single called instead of byte');
+    halt(1)
+  end;
+
+var
+  v: variant;
+  x: byte;
+  y: single;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+end.

+ 42 - 0
tests/test/cg/variants/tvarol121.pp

@@ -0,0 +1,42 @@
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = currency;
+{$endif FPC_COMP_IS_INT64}
+procedure test(a: byte); overload;
+  begin
+    writeln('byte called instead of double');
+    writeln('XXX')
+  end;
+
+procedure test(a: double); overload;
+  begin
+    writeln('double called instead of byte');
+    halt(1)
+  end;
+
+var
+  v: variant;
+  x: byte;
+  y: double;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+end.

+ 42 - 0
tests/test/cg/variants/tvarol122.pp

@@ -0,0 +1,42 @@
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = currency;
+{$endif FPC_COMP_IS_INT64}
+procedure test(a: byte); overload;
+  begin
+    writeln('byte called instead of extended');
+    writeln('XXX')
+  end;
+
+procedure test(a: extended); overload;
+  begin
+    writeln('extended called instead of byte');
+    halt(1)
+  end;
+
+var
+  v: variant;
+  x: byte;
+  y: extended;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+end.

+ 42 - 0
tests/test/cg/variants/tvarol123.pp

@@ -0,0 +1,42 @@
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = double;
+{$endif FPC_COMP_IS_INT64}
+procedure test(a: byte); overload;
+  begin
+    writeln('byte called instead of char');
+    writeln('XXX')
+  end;
+
+procedure test(a: char); overload;
+  begin
+    writeln('char called instead of byte');
+    halt(1)
+  end;
+
+var
+  v: variant;
+  x: byte;
+  y: char;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      writeln('VVV');
+  end;
+end.

+ 43 - 0
tests/test/cg/variants/tvarol124.pp

@@ -0,0 +1,43 @@
+{ %fail }
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = double;
+{$endif FPC_COMP_IS_INT64}
+procedure test(a: byte); overload;
+  begin
+    writeln('byte called instead of boolean');
+    writeln('XXX')
+  end;
+
+procedure test(a: boolean); overload;
+  begin
+    writeln('boolean called instead of byte');
+    writeln('YYY')
+  end;
+
+var
+  v: variant;
+  x: byte;
+  y: boolean;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      writeln('QQQ');
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      writeln('VVV');
+  end;
+end.

+ 42 - 0
tests/test/cg/variants/tvarol125.pp

@@ -0,0 +1,42 @@
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = double;
+{$endif FPC_COMP_IS_INT64}
+procedure test(a: byte); overload;
+  begin
+    writeln('byte called instead of widestring');
+    writeln('XXX')
+  end;
+
+procedure test(a: widestring); overload;
+  begin
+    writeln('widestring called instead of byte');
+    halt(1)
+  end;
+
+var
+  v: variant;
+  x: byte;
+  y: widestring;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      writeln('VVV');
+  end;
+end.

+ 42 - 0
tests/test/cg/variants/tvarol126.pp

@@ -0,0 +1,42 @@
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = double;
+{$endif FPC_COMP_IS_INT64}
+procedure test(a: byte); overload;
+  begin
+    writeln('byte called instead of widechar');
+    writeln('XXX')
+  end;
+
+procedure test(a: widechar); overload;
+  begin
+    writeln('widechar called instead of byte');
+    halt(1)
+  end;
+
+var
+  v: variant;
+  x: byte;
+  y: widechar;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+end.

+ 42 - 0
tests/test/cg/variants/tvarol127.pp

@@ -0,0 +1,42 @@
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = double;
+{$endif FPC_COMP_IS_INT64}
+procedure test(a: shortint); overload;
+  begin
+    writeln('shortint called instead of shortstring');
+    writeln('XXX')
+  end;
+
+procedure test(a: shortstring); overload;
+  begin
+    writeln('shortstring called instead of shortint');
+    halt(1)
+  end;
+
+var
+  v: variant;
+  x: shortint;
+  y: shortstring;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      writeln('VVV');
+  end;
+end.

+ 42 - 0
tests/test/cg/variants/tvarol128.pp

@@ -0,0 +1,42 @@
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = double;
+{$endif FPC_COMP_IS_INT64}
+procedure test(a: shortint); overload;
+  begin
+    writeln('shortint called instead of ansistring');
+    writeln('XXX')
+  end;
+
+procedure test(a: ansistring); overload;
+  begin
+    writeln('ansistring called instead of shortint');
+    halt(1)
+  end;
+
+var
+  v: variant;
+  x: shortint;
+  y: ansistring;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      writeln('VVV');
+  end;
+end.

+ 42 - 0
tests/test/cg/variants/tvarol129.pp

@@ -0,0 +1,42 @@
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = double;
+{$endif FPC_COMP_IS_INT64}
+procedure test(a: shortint); overload;
+  begin
+    writeln('shortint called instead of single');
+    writeln('XXX')
+  end;
+
+procedure test(a: single); overload;
+  begin
+    writeln('single called instead of shortint');
+    halt(1)
+  end;
+
+var
+  v: variant;
+  x: shortint;
+  y: single;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+end.

+ 43 - 0
tests/test/cg/variants/tvarol13.pp

@@ -0,0 +1,43 @@
+{ %fail }
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = currency;
+{$endif FPC_COMP_IS_INT64}
+procedure test(var a); overload;
+  begin
+    writeln('formal called instead of double');
+    writeln('XXX')
+  end;
+
+procedure test(a: double); overload;
+  begin
+    writeln('double called instead of formal');
+    writeln('YYY')
+  end;
+
+var
+  v: variant;
+  x: longint;
+  y: double;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      writeln('QQQ');
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      writeln('VVV');
+  end;
+end.

+ 42 - 0
tests/test/cg/variants/tvarol130.pp

@@ -0,0 +1,42 @@
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = currency;
+{$endif FPC_COMP_IS_INT64}
+procedure test(a: shortint); overload;
+  begin
+    writeln('shortint called instead of double');
+    writeln('XXX')
+  end;
+
+procedure test(a: double); overload;
+  begin
+    writeln('double called instead of shortint');
+    halt(1)
+  end;
+
+var
+  v: variant;
+  x: shortint;
+  y: double;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+end.

+ 42 - 0
tests/test/cg/variants/tvarol131.pp

@@ -0,0 +1,42 @@
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = currency;
+{$endif FPC_COMP_IS_INT64}
+procedure test(a: shortint); overload;
+  begin
+    writeln('shortint called instead of extended');
+    writeln('XXX')
+  end;
+
+procedure test(a: extended); overload;
+  begin
+    writeln('extended called instead of shortint');
+    halt(1)
+  end;
+
+var
+  v: variant;
+  x: shortint;
+  y: extended;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+end.

+ 42 - 0
tests/test/cg/variants/tvarol132.pp

@@ -0,0 +1,42 @@
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = double;
+{$endif FPC_COMP_IS_INT64}
+procedure test(a: shortint); overload;
+  begin
+    writeln('shortint called instead of char');
+    writeln('XXX')
+  end;
+
+procedure test(a: char); overload;
+  begin
+    writeln('char called instead of shortint');
+    halt(1)
+  end;
+
+var
+  v: variant;
+  x: shortint;
+  y: char;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      writeln('VVV');
+  end;
+end.

+ 43 - 0
tests/test/cg/variants/tvarol133.pp

@@ -0,0 +1,43 @@
+{ %fail }
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = double;
+{$endif FPC_COMP_IS_INT64}
+procedure test(a: shortint); overload;
+  begin
+    writeln('shortint called instead of boolean');
+    writeln('XXX')
+  end;
+
+procedure test(a: boolean); overload;
+  begin
+    writeln('boolean called instead of shortint');
+    writeln('YYY')
+  end;
+
+var
+  v: variant;
+  x: shortint;
+  y: boolean;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      writeln('QQQ');
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      writeln('VVV');
+  end;
+end.

+ 42 - 0
tests/test/cg/variants/tvarol134.pp

@@ -0,0 +1,42 @@
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = double;
+{$endif FPC_COMP_IS_INT64}
+procedure test(a: shortint); overload;
+  begin
+    writeln('shortint called instead of widestring');
+    writeln('XXX')
+  end;
+
+procedure test(a: widestring); overload;
+  begin
+    writeln('widestring called instead of shortint');
+    halt(1)
+  end;
+
+var
+  v: variant;
+  x: shortint;
+  y: widestring;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      writeln('VVV');
+  end;
+end.

+ 42 - 0
tests/test/cg/variants/tvarol135.pp

@@ -0,0 +1,42 @@
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = double;
+{$endif FPC_COMP_IS_INT64}
+procedure test(a: shortint); overload;
+  begin
+    writeln('shortint called instead of widechar');
+    writeln('XXX')
+  end;
+
+procedure test(a: widechar); overload;
+  begin
+    writeln('widechar called instead of shortint');
+    halt(1)
+  end;
+
+var
+  v: variant;
+  x: shortint;
+  y: widechar;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+end.

+ 42 - 0
tests/test/cg/variants/tvarol136.pp

@@ -0,0 +1,42 @@
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = double;
+{$endif FPC_COMP_IS_INT64}
+procedure test(a: shortstring); overload;
+  begin
+    writeln('shortstring called instead of ansistring');
+    writeln('XXX')
+  end;
+
+procedure test(a: ansistring); overload;
+  begin
+    writeln('ansistring called instead of shortstring');
+    halt(1)
+  end;
+
+var
+  v: variant;
+  x: shortstring;
+  y: ansistring;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+end.

+ 42 - 0
tests/test/cg/variants/tvarol137.pp

@@ -0,0 +1,42 @@
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = double;
+{$endif FPC_COMP_IS_INT64}
+procedure test(a: shortstring); overload;
+  begin
+    writeln('shortstring called instead of single');
+    halt(1)
+  end;
+
+procedure test(a: single); overload;
+  begin
+    writeln('single called instead of shortstring');
+    writeln('YYY')
+  end;
+
+var
+  v: variant;
+  x: shortstring;
+  y: single;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      writeln('QQQ');
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+end.

+ 42 - 0
tests/test/cg/variants/tvarol138.pp

@@ -0,0 +1,42 @@
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = currency;
+{$endif FPC_COMP_IS_INT64}
+procedure test(a: shortstring); overload;
+  begin
+    writeln('shortstring called instead of double');
+    halt(1)
+  end;
+
+procedure test(a: double); overload;
+  begin
+    writeln('double called instead of shortstring');
+    writeln('YYY')
+  end;
+
+var
+  v: variant;
+  x: shortstring;
+  y: double;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      writeln('QQQ');
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+end.

+ 42 - 0
tests/test/cg/variants/tvarol139.pp

@@ -0,0 +1,42 @@
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = currency;
+{$endif FPC_COMP_IS_INT64}
+procedure test(a: shortstring); overload;
+  begin
+    writeln('shortstring called instead of extended');
+    halt(1)
+  end;
+
+procedure test(a: extended); overload;
+  begin
+    writeln('extended called instead of shortstring');
+    writeln('YYY')
+  end;
+
+var
+  v: variant;
+  x: shortstring;
+  y: extended;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      writeln('QQQ');
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+end.

+ 43 - 0
tests/test/cg/variants/tvarol14.pp

@@ -0,0 +1,43 @@
+{ %fail }
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = currency;
+{$endif FPC_COMP_IS_INT64}
+procedure test(var a); overload;
+  begin
+    writeln('formal called instead of extended');
+    writeln('XXX')
+  end;
+
+procedure test(a: extended); overload;
+  begin
+    writeln('extended called instead of formal');
+    writeln('YYY')
+  end;
+
+var
+  v: variant;
+  x: longint;
+  y: extended;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      writeln('QQQ');
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      writeln('VVV');
+  end;
+end.

+ 42 - 0
tests/test/cg/variants/tvarol140.pp

@@ -0,0 +1,42 @@
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = double;
+{$endif FPC_COMP_IS_INT64}
+procedure test(a: shortstring); overload;
+  begin
+    writeln('shortstring called instead of char');
+    writeln('XXX')
+  end;
+
+procedure test(a: char); overload;
+  begin
+    writeln('char called instead of shortstring');
+    halt(1)
+  end;
+
+var
+  v: variant;
+  x: shortstring;
+  y: char;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+end.

+ 42 - 0
tests/test/cg/variants/tvarol141.pp

@@ -0,0 +1,42 @@
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = double;
+{$endif FPC_COMP_IS_INT64}
+procedure test(a: shortstring); overload;
+  begin
+    writeln('shortstring called instead of boolean');
+    halt(1)
+  end;
+
+procedure test(a: boolean); overload;
+  begin
+    writeln('boolean called instead of shortstring');
+    writeln('YYY')
+  end;
+
+var
+  v: variant;
+  x: shortstring;
+  y: boolean;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      writeln('QQQ');
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+end.

+ 42 - 0
tests/test/cg/variants/tvarol142.pp

@@ -0,0 +1,42 @@
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = double;
+{$endif FPC_COMP_IS_INT64}
+procedure test(a: shortstring); overload;
+  begin
+    writeln('shortstring called instead of widestring');
+    writeln('XXX')
+  end;
+
+procedure test(a: widestring); overload;
+  begin
+    writeln('widestring called instead of shortstring');
+    halt(1)
+  end;
+
+var
+  v: variant;
+  x: shortstring;
+  y: widestring;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+end.

+ 42 - 0
tests/test/cg/variants/tvarol143.pp

@@ -0,0 +1,42 @@
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = double;
+{$endif FPC_COMP_IS_INT64}
+procedure test(a: shortstring); overload;
+  begin
+    writeln('shortstring called instead of widechar');
+    writeln('XXX')
+  end;
+
+procedure test(a: widechar); overload;
+  begin
+    writeln('widechar called instead of shortstring');
+    halt(1)
+  end;
+
+var
+  v: variant;
+  x: shortstring;
+  y: widechar;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+end.

+ 42 - 0
tests/test/cg/variants/tvarol144.pp

@@ -0,0 +1,42 @@
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = double;
+{$endif FPC_COMP_IS_INT64}
+procedure test(a: ansistring); overload;
+  begin
+    writeln('ansistring called instead of single');
+    halt(1)
+  end;
+
+procedure test(a: single); overload;
+  begin
+    writeln('single called instead of ansistring');
+    writeln('YYY')
+  end;
+
+var
+  v: variant;
+  x: ansistring;
+  y: single;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      writeln('QQQ');
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+end.

+ 42 - 0
tests/test/cg/variants/tvarol145.pp

@@ -0,0 +1,42 @@
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = currency;
+{$endif FPC_COMP_IS_INT64}
+procedure test(a: ansistring); overload;
+  begin
+    writeln('ansistring called instead of double');
+    halt(1)
+  end;
+
+procedure test(a: double); overload;
+  begin
+    writeln('double called instead of ansistring');
+    writeln('YYY')
+  end;
+
+var
+  v: variant;
+  x: ansistring;
+  y: double;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      writeln('QQQ');
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+end.

+ 42 - 0
tests/test/cg/variants/tvarol146.pp

@@ -0,0 +1,42 @@
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = currency;
+{$endif FPC_COMP_IS_INT64}
+procedure test(a: ansistring); overload;
+  begin
+    writeln('ansistring called instead of extended');
+    halt(1)
+  end;
+
+procedure test(a: extended); overload;
+  begin
+    writeln('extended called instead of ansistring');
+    writeln('YYY')
+  end;
+
+var
+  v: variant;
+  x: ansistring;
+  y: extended;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      writeln('QQQ');
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+end.

+ 42 - 0
tests/test/cg/variants/tvarol147.pp

@@ -0,0 +1,42 @@
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = double;
+{$endif FPC_COMP_IS_INT64}
+procedure test(a: ansistring); overload;
+  begin
+    writeln('ansistring called instead of char');
+    writeln('XXX')
+  end;
+
+procedure test(a: char); overload;
+  begin
+    writeln('char called instead of ansistring');
+    halt(1)
+  end;
+
+var
+  v: variant;
+  x: ansistring;
+  y: char;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+end.

+ 42 - 0
tests/test/cg/variants/tvarol148.pp

@@ -0,0 +1,42 @@
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = double;
+{$endif FPC_COMP_IS_INT64}
+procedure test(a: ansistring); overload;
+  begin
+    writeln('ansistring called instead of boolean');
+    halt(1)
+  end;
+
+procedure test(a: boolean); overload;
+  begin
+    writeln('boolean called instead of ansistring');
+    writeln('YYY')
+  end;
+
+var
+  v: variant;
+  x: ansistring;
+  y: boolean;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      writeln('QQQ');
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+end.

+ 42 - 0
tests/test/cg/variants/tvarol149.pp

@@ -0,0 +1,42 @@
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = double;
+{$endif FPC_COMP_IS_INT64}
+procedure test(a: ansistring); overload;
+  begin
+    writeln('ansistring called instead of widestring');
+    writeln('XXX')
+  end;
+
+procedure test(a: widestring); overload;
+  begin
+    writeln('widestring called instead of ansistring');
+    halt(1)
+  end;
+
+var
+  v: variant;
+  x: ansistring;
+  y: widestring;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+end.

+ 42 - 0
tests/test/cg/variants/tvarol15.pp

@@ -0,0 +1,42 @@
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = double;
+{$endif FPC_COMP_IS_INT64}
+procedure test(var a); overload;
+  begin
+    writeln('formal called instead of char');
+    writeln('XXX')
+  end;
+
+procedure test(a: char); overload;
+  begin
+    writeln('char called instead of formal');
+    halt(1)
+  end;
+
+var
+  v: variant;
+  x: longint;
+  y: char;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+end.

+ 42 - 0
tests/test/cg/variants/tvarol150.pp

@@ -0,0 +1,42 @@
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = double;
+{$endif FPC_COMP_IS_INT64}
+procedure test(a: ansistring); overload;
+  begin
+    writeln('ansistring called instead of widechar');
+    writeln('XXX')
+  end;
+
+procedure test(a: widechar); overload;
+  begin
+    writeln('widechar called instead of ansistring');
+    halt(1)
+  end;
+
+var
+  v: variant;
+  x: ansistring;
+  y: widechar;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+end.

+ 42 - 0
tests/test/cg/variants/tvarol151.pp

@@ -0,0 +1,42 @@
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = currency;
+{$endif FPC_COMP_IS_INT64}
+procedure test(a: single); overload;
+  begin
+    writeln('single called instead of double');
+    writeln('XXX')
+  end;
+
+procedure test(a: double); overload;
+  begin
+    writeln('double called instead of single');
+    halt(1)
+  end;
+
+var
+  v: variant;
+  x: single;
+  y: double;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+end.

+ 42 - 0
tests/test/cg/variants/tvarol152.pp

@@ -0,0 +1,42 @@
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = currency;
+{$endif FPC_COMP_IS_INT64}
+procedure test(a: single); overload;
+  begin
+    writeln('single called instead of extended');
+    writeln('XXX')
+  end;
+
+procedure test(a: extended); overload;
+  begin
+    writeln('extended called instead of single');
+    halt(1)
+  end;
+
+var
+  v: variant;
+  x: single;
+  y: extended;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+end.

+ 42 - 0
tests/test/cg/variants/tvarol153.pp

@@ -0,0 +1,42 @@
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = double;
+{$endif FPC_COMP_IS_INT64}
+procedure test(a: single); overload;
+  begin
+    writeln('single called instead of char');
+    writeln('XXX')
+  end;
+
+procedure test(a: char); overload;
+  begin
+    writeln('char called instead of single');
+    halt(1)
+  end;
+
+var
+  v: variant;
+  x: single;
+  y: char;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      writeln('VVV');
+  end;
+end.

+ 43 - 0
tests/test/cg/variants/tvarol154.pp

@@ -0,0 +1,43 @@
+{ %fail }
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = double;
+{$endif FPC_COMP_IS_INT64}
+procedure test(a: single); overload;
+  begin
+    writeln('single called instead of boolean');
+    writeln('XXX')
+  end;
+
+procedure test(a: boolean); overload;
+  begin
+    writeln('boolean called instead of single');
+    writeln('YYY')
+  end;
+
+var
+  v: variant;
+  x: single;
+  y: boolean;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      writeln('QQQ');
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      writeln('VVV');
+  end;
+end.

+ 42 - 0
tests/test/cg/variants/tvarol155.pp

@@ -0,0 +1,42 @@
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = double;
+{$endif FPC_COMP_IS_INT64}
+procedure test(a: single); overload;
+  begin
+    writeln('single called instead of widestring');
+    writeln('XXX')
+  end;
+
+procedure test(a: widestring); overload;
+  begin
+    writeln('widestring called instead of single');
+    halt(1)
+  end;
+
+var
+  v: variant;
+  x: single;
+  y: widestring;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      writeln('VVV');
+  end;
+end.

+ 42 - 0
tests/test/cg/variants/tvarol156.pp

@@ -0,0 +1,42 @@
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = double;
+{$endif FPC_COMP_IS_INT64}
+procedure test(a: single); overload;
+  begin
+    writeln('single called instead of widechar');
+    writeln('XXX')
+  end;
+
+procedure test(a: widechar); overload;
+  begin
+    writeln('widechar called instead of single');
+    halt(1)
+  end;
+
+var
+  v: variant;
+  x: single;
+  y: widechar;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+end.

+ 46 - 0
tests/test/cg/variants/tvarol157.pp

@@ -0,0 +1,46 @@
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = currency;
+{$endif FPC_COMP_IS_INT64}
+{$ifdef FPC_HAS_TYPE_EXTENDED}
+procedure test(a: double); overload;
+  begin
+    writeln('double called instead of extended');
+    writeln('XXX')
+  end;
+
+procedure test(a: extended); overload;
+  begin
+    writeln('extended called instead of double');
+    writeln('YYY')
+  end;
+
+var
+  v: variant;
+  x: double;
+  y: extended;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+{$else}
+begin
+{$endif}
+end.

+ 42 - 0
tests/test/cg/variants/tvarol158.pp

@@ -0,0 +1,42 @@
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = double;
+{$endif FPC_COMP_IS_INT64}
+procedure test(a: double); overload;
+  begin
+    writeln('double called instead of char');
+    writeln('XXX')
+  end;
+
+procedure test(a: char); overload;
+  begin
+    writeln('char called instead of double');
+    halt(1)
+  end;
+
+var
+  v: variant;
+  x: double;
+  y: char;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      writeln('VVV');
+  end;
+end.

+ 43 - 0
tests/test/cg/variants/tvarol159.pp

@@ -0,0 +1,43 @@
+{ %fail }
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = double;
+{$endif FPC_COMP_IS_INT64}
+procedure test(a: double); overload;
+  begin
+    writeln('double called instead of boolean');
+    writeln('XXX')
+  end;
+
+procedure test(a: boolean); overload;
+  begin
+    writeln('boolean called instead of double');
+    writeln('YYY')
+  end;
+
+var
+  v: variant;
+  x: double;
+  y: boolean;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      writeln('QQQ');
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      writeln('VVV');
+  end;
+end.

+ 43 - 0
tests/test/cg/variants/tvarol16.pp

@@ -0,0 +1,43 @@
+{ %fail }
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = double;
+{$endif FPC_COMP_IS_INT64}
+procedure test(var a); overload;
+  begin
+    writeln('formal called instead of boolean');
+    writeln('XXX')
+  end;
+
+procedure test(a: boolean); overload;
+  begin
+    writeln('boolean called instead of formal');
+    writeln('YYY')
+  end;
+
+var
+  v: variant;
+  x: longint;
+  y: boolean;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      writeln('QQQ');
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      writeln('VVV');
+  end;
+end.

+ 42 - 0
tests/test/cg/variants/tvarol160.pp

@@ -0,0 +1,42 @@
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = double;
+{$endif FPC_COMP_IS_INT64}
+procedure test(a: double); overload;
+  begin
+    writeln('double called instead of widestring');
+    writeln('XXX')
+  end;
+
+procedure test(a: widestring); overload;
+  begin
+    writeln('widestring called instead of double');
+    halt(1)
+  end;
+
+var
+  v: variant;
+  x: double;
+  y: widestring;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      writeln('VVV');
+  end;
+end.

+ 42 - 0
tests/test/cg/variants/tvarol161.pp

@@ -0,0 +1,42 @@
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = double;
+{$endif FPC_COMP_IS_INT64}
+procedure test(a: double); overload;
+  begin
+    writeln('double called instead of widechar');
+    writeln('XXX')
+  end;
+
+procedure test(a: widechar); overload;
+  begin
+    writeln('widechar called instead of double');
+    halt(1)
+  end;
+
+var
+  v: variant;
+  x: double;
+  y: widechar;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+end.

+ 42 - 0
tests/test/cg/variants/tvarol162.pp

@@ -0,0 +1,42 @@
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = double;
+{$endif FPC_COMP_IS_INT64}
+procedure test(a: extended); overload;
+  begin
+    writeln('extended called instead of char');
+    writeln('XXX')
+  end;
+
+procedure test(a: char); overload;
+  begin
+    writeln('char called instead of extended');
+    halt(1)
+  end;
+
+var
+  v: variant;
+  x: extended;
+  y: char;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      writeln('VVV');
+  end;
+end.

+ 43 - 0
tests/test/cg/variants/tvarol163.pp

@@ -0,0 +1,43 @@
+{ %fail }
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = double;
+{$endif FPC_COMP_IS_INT64}
+procedure test(a: extended); overload;
+  begin
+    writeln('extended called instead of boolean');
+    writeln('XXX')
+  end;
+
+procedure test(a: boolean); overload;
+  begin
+    writeln('boolean called instead of extended');
+    writeln('YYY')
+  end;
+
+var
+  v: variant;
+  x: extended;
+  y: boolean;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      writeln('QQQ');
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      writeln('VVV');
+  end;
+end.

+ 42 - 0
tests/test/cg/variants/tvarol164.pp

@@ -0,0 +1,42 @@
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = double;
+{$endif FPC_COMP_IS_INT64}
+procedure test(a: extended); overload;
+  begin
+    writeln('extended called instead of widestring');
+    writeln('XXX')
+  end;
+
+procedure test(a: widestring); overload;
+  begin
+    writeln('widestring called instead of extended');
+    halt(1)
+  end;
+
+var
+  v: variant;
+  x: extended;
+  y: widestring;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      writeln('VVV');
+  end;
+end.

+ 42 - 0
tests/test/cg/variants/tvarol165.pp

@@ -0,0 +1,42 @@
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = double;
+{$endif FPC_COMP_IS_INT64}
+procedure test(a: extended); overload;
+  begin
+    writeln('extended called instead of widechar');
+    writeln('XXX')
+  end;
+
+procedure test(a: widechar); overload;
+  begin
+    writeln('widechar called instead of extended');
+    halt(1)
+  end;
+
+var
+  v: variant;
+  x: extended;
+  y: widechar;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+end.

+ 42 - 0
tests/test/cg/variants/tvarol166.pp

@@ -0,0 +1,42 @@
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = double;
+{$endif FPC_COMP_IS_INT64}
+procedure test(a: char); overload;
+  begin
+    writeln('char called instead of boolean');
+    halt(1)
+  end;
+
+procedure test(a: boolean); overload;
+  begin
+    writeln('boolean called instead of char');
+    writeln('YYY')
+  end;
+
+var
+  v: variant;
+  x: char;
+  y: boolean;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      writeln('QQQ');
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+end.

+ 42 - 0
tests/test/cg/variants/tvarol167.pp

@@ -0,0 +1,42 @@
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = double;
+{$endif FPC_COMP_IS_INT64}
+procedure test(a: char); overload;
+  begin
+    writeln('char called instead of widestring');
+    halt(1)
+  end;
+
+procedure test(a: widestring); overload;
+  begin
+    writeln('widestring called instead of char');
+    writeln('YYY')
+  end;
+
+var
+  v: variant;
+  x: char;
+  y: widestring;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+end.

+ 43 - 0
tests/test/cg/variants/tvarol168.pp

@@ -0,0 +1,43 @@
+{ %fail }
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = double;
+{$endif FPC_COMP_IS_INT64}
+procedure test(a: char); overload;
+  begin
+    writeln('char called instead of widechar');
+    writeln('XXX')
+  end;
+
+procedure test(a: widechar); overload;
+  begin
+    writeln('widechar called instead of char');
+    writeln('YYY')
+  end;
+
+var
+  v: variant;
+  x: char;
+  y: widechar;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      writeln('QQQ');
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      writeln('VVV');
+  end;
+end.

+ 42 - 0
tests/test/cg/variants/tvarol169.pp

@@ -0,0 +1,42 @@
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = double;
+{$endif FPC_COMP_IS_INT64}
+procedure test(a: boolean); overload;
+  begin
+    writeln('boolean called instead of widestring');
+    writeln('XXX')
+  end;
+
+procedure test(a: widestring); overload;
+  begin
+    writeln('widestring called instead of boolean');
+    halt(1)
+  end;
+
+var
+  v: variant;
+  x: boolean;
+  y: widestring;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      writeln('VVV');
+  end;
+end.

+ 42 - 0
tests/test/cg/variants/tvarol17.pp

@@ -0,0 +1,42 @@
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = double;
+{$endif FPC_COMP_IS_INT64}
+procedure test(var a); overload;
+  begin
+    writeln('formal called instead of widestring');
+    writeln('XXX')
+  end;
+
+procedure test(a: widestring); overload;
+  begin
+    writeln('widestring called instead of formal');
+    halt(1)
+  end;
+
+var
+  v: variant;
+  x: longint;
+  y: widestring;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+end.

+ 42 - 0
tests/test/cg/variants/tvarol170.pp

@@ -0,0 +1,42 @@
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = double;
+{$endif FPC_COMP_IS_INT64}
+procedure test(a: boolean); overload;
+  begin
+    writeln('boolean called instead of widechar');
+    writeln('XXX')
+  end;
+
+procedure test(a: widechar); overload;
+  begin
+    writeln('widechar called instead of boolean');
+    halt(1)
+  end;
+
+var
+  v: variant;
+  x: boolean;
+  y: widechar;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+end.

+ 42 - 0
tests/test/cg/variants/tvarol171.pp

@@ -0,0 +1,42 @@
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = double;
+{$endif FPC_COMP_IS_INT64}
+procedure test(a: widestring); overload;
+  begin
+    writeln('widestring called instead of widechar');
+    writeln('XXX')
+  end;
+
+procedure test(a: widechar); overload;
+  begin
+    writeln('widechar called instead of widestring');
+    halt(1)
+  end;
+
+var
+  v: variant;
+  x: widestring;
+  y: widechar;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+end.

+ 42 - 0
tests/test/cg/variants/tvarol18.pp

@@ -0,0 +1,42 @@
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = double;
+{$endif FPC_COMP_IS_INT64}
+procedure test(var a); overload;
+  begin
+    writeln('formal called instead of widechar');
+    writeln('XXX')
+  end;
+
+procedure test(a: widechar); overload;
+  begin
+    writeln('widechar called instead of formal');
+    halt(1)
+  end;
+
+var
+  v: variant;
+  x: longint;
+  y: widechar;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+end.

+ 42 - 0
tests/test/cg/variants/tvarol19.pp

@@ -0,0 +1,42 @@
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = double;
+{$endif FPC_COMP_IS_INT64}
+procedure test(a: comp); overload;
+  begin
+    writeln('comp called instead of int64');
+    writeln('XXX')
+  end;
+
+procedure test(a: int64); overload;
+  begin
+    writeln('int64 called instead of comp');
+    halt(1)
+  end;
+
+var
+  v: variant;
+  x: comp;
+  y: int64;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+end.

+ 42 - 0
tests/test/cg/variants/tvarol2.pp

@@ -0,0 +1,42 @@
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = double;
+{$endif FPC_COMP_IS_INT64}
+procedure test(var a); overload;
+  begin
+    writeln('formal called instead of int64');
+    writeln('XXX')
+  end;
+
+procedure test(a: int64); overload;
+  begin
+    writeln('int64 called instead of formal');
+    halt(1)
+  end;
+
+var
+  v: variant;
+  x: longint;
+  y: int64;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+end.

+ 43 - 0
tests/test/cg/variants/tvarol20.pp

@@ -0,0 +1,43 @@
+{ %fail }
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = double;
+{$endif FPC_COMP_IS_INT64}
+procedure test(a: comp); overload;
+  begin
+    writeln('comp called instead of currency');
+    writeln('XXX')
+  end;
+
+procedure test(a: currency); overload;
+  begin
+    writeln('currency called instead of comp');
+    writeln('YYY')
+  end;
+
+var
+  v: variant;
+  x: comp;
+  y: currency;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      writeln('QQQ');
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      writeln('VVV');
+  end;
+end.

+ 42 - 0
tests/test/cg/variants/tvarol21.pp

@@ -0,0 +1,42 @@
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = double;
+{$endif FPC_COMP_IS_INT64}
+procedure test(a: comp); overload;
+  begin
+    writeln('comp called instead of longint');
+    halt(1)
+  end;
+
+procedure test(a: longint); overload;
+  begin
+    writeln('longint called instead of comp');
+    writeln('YYY')
+  end;
+
+var
+  v: variant;
+  x: comp;
+  y: longint;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+end.

+ 42 - 0
tests/test/cg/variants/tvarol22.pp

@@ -0,0 +1,42 @@
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = double;
+{$endif FPC_COMP_IS_INT64}
+procedure test(a: comp); overload;
+  begin
+    writeln('comp called instead of cardinal');
+    halt(1)
+  end;
+
+procedure test(a: cardinal); overload;
+  begin
+    writeln('cardinal called instead of comp');
+    writeln('YYY')
+  end;
+
+var
+  v: variant;
+  x: comp;
+  y: cardinal;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+end.

+ 42 - 0
tests/test/cg/variants/tvarol23.pp

@@ -0,0 +1,42 @@
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = double;
+{$endif FPC_COMP_IS_INT64}
+procedure test(a: comp); overload;
+  begin
+    writeln('comp called instead of word');
+    halt(1)
+  end;
+
+procedure test(a: word); overload;
+  begin
+    writeln('word called instead of comp');
+    writeln('YYY')
+  end;
+
+var
+  v: variant;
+  x: comp;
+  y: word;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+end.

+ 42 - 0
tests/test/cg/variants/tvarol24.pp

@@ -0,0 +1,42 @@
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = double;
+{$endif FPC_COMP_IS_INT64}
+procedure test(a: comp); overload;
+  begin
+    writeln('comp called instead of smallint');
+    halt(1)
+  end;
+
+procedure test(a: smallint); overload;
+  begin
+    writeln('smallint called instead of comp');
+    writeln('YYY')
+  end;
+
+var
+  v: variant;
+  x: comp;
+  y: smallint;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+end.

+ 42 - 0
tests/test/cg/variants/tvarol25.pp

@@ -0,0 +1,42 @@
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = double;
+{$endif FPC_COMP_IS_INT64}
+procedure test(a: comp); overload;
+  begin
+    writeln('comp called instead of byte');
+    halt(1)
+  end;
+
+procedure test(a: byte); overload;
+  begin
+    writeln('byte called instead of comp');
+    writeln('YYY')
+  end;
+
+var
+  v: variant;
+  x: comp;
+  y: byte;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+end.

+ 42 - 0
tests/test/cg/variants/tvarol26.pp

@@ -0,0 +1,42 @@
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = double;
+{$endif FPC_COMP_IS_INT64}
+procedure test(a: comp); overload;
+  begin
+    writeln('comp called instead of shortint');
+    halt(1)
+  end;
+
+procedure test(a: shortint); overload;
+  begin
+    writeln('shortint called instead of comp');
+    writeln('YYY')
+  end;
+
+var
+  v: variant;
+  x: comp;
+  y: shortint;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+end.

+ 42 - 0
tests/test/cg/variants/tvarol27.pp

@@ -0,0 +1,42 @@
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = double;
+{$endif FPC_COMP_IS_INT64}
+procedure test(a: comp); overload;
+  begin
+    writeln('comp called instead of shortstring');
+    writeln('XXX')
+  end;
+
+procedure test(a: shortstring); overload;
+  begin
+    writeln('shortstring called instead of comp');
+    halt(1)
+  end;
+
+var
+  v: variant;
+  x: comp;
+  y: shortstring;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      writeln('VVV');
+  end;
+end.

+ 42 - 0
tests/test/cg/variants/tvarol28.pp

@@ -0,0 +1,42 @@
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = double;
+{$endif FPC_COMP_IS_INT64}
+procedure test(a: comp); overload;
+  begin
+    writeln('comp called instead of ansistring');
+    writeln('XXX')
+  end;
+
+procedure test(a: ansistring); overload;
+  begin
+    writeln('ansistring called instead of comp');
+    halt(1)
+  end;
+
+var
+  v: variant;
+  x: comp;
+  y: ansistring;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      writeln('VVV');
+  end;
+end.

+ 42 - 0
tests/test/cg/variants/tvarol29.pp

@@ -0,0 +1,42 @@
+{$ifdef fpc}
+{$mode delphi}
+{$endif fpc}
+
+{$ifdef FPC_COMP_IS_INT64}
+type 
+  comp = double;
+{$endif FPC_COMP_IS_INT64}
+procedure test(a: comp); overload;
+  begin
+    writeln('comp called instead of single');
+    halt(1)
+  end;
+
+procedure test(a: single); overload;
+  begin
+    writeln('single called instead of comp');
+    writeln('YYY')
+  end;
+
+var
+  v: variant;
+  x: comp;
+  y: single;
+
+begin
+  try
+    v := x;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+
+  try
+    v := y;
+    test(v);
+  except
+    on E : TObject do
+      halt(1);
+  end;
+end.

Některé soubory nejsou zobrazeny, neboť je v těchto rozdílových datech změněno mnoho souborů