Skip to content

Commit ea23eef

Browse files
committed
fbc: sf.net #843: Implicit casting of argument to string works for Instr() and Mid() but not for Left() and Right()
1 parent 9825062 commit ea23eef

File tree

5 files changed

+32
-9
lines changed

5 files changed

+32
-9
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ Version 1.09.0
3838
- darwin: a variety of improvements to allow compiling and linking (TeeEmCee)
3939
- gfxlib2: fix d2d scaling issues for high dpi (adeyblue)
4040
- fbc: improve error message on statement between SELECT and first CASE inside a subroutine and don't allow CONST/ENUM between any SELECT & first CASE.
41+
- sf.net #843: Implicit casting of argument to string works for Instr() and Mid() but not for Left() and Right()
4142

4243

4344
Version 1.08.0

src/compiler/symb-data.bas

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ sub symbDataInit( )
134134
'' populate symb_dtypeMatchTB() with ranking numbers
135135
for i = 0 to NUMTYPES - 1
136136
dtype2 = rank(i)
137-
symb_dtypeMatchTB( dtype1, dtype2 ) = i
137+
symb_dtypeMatchTB( dtype1, dtype2 ) = i * FB_OVLPROC_CONVSCALE
138138
next
139139

140140
next
@@ -533,6 +533,8 @@ end function
533533
'' FB_OVLPROC_LOWEST_MATCH => compatible, lowest scoring parameter
534534
'' FB_OVLPROC_NO_MATCH => incompatible
535535

536+
'' FB_OVLPROC_CONVSCALE => granularity of the matching score
537+
536538
''
537539
function typeCalcMatch _
538540
( _
@@ -558,7 +560,7 @@ function typeCalcMatch _
558560
end if
559561

560562
if( (typeGetDtAndPtrOnly( ldtype ) = typeGetDtAndPtrOnly( rdtype )) and (lsubtype = rsubtype) ) then
561-
return FB_OVLPROC_TYPEMATCH + const_matches
563+
return FB_OVLPROC_TYPEMATCH + const_matches * FB_OVLPROC_CONVSCALE
562564
end if
563565

564566
'' We know that they're different (in terms of dtype or subtype or both),

src/compiler/symb-proc.bas

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1639,7 +1639,7 @@ end function
16391639
rec_cnt -= 1
16401640

16411641
if( proc <> NULL ) then
1642-
return FB_OVLPROC_HALFMATCH - FB_DATATYPE_STRUCT
1642+
return FB_OVLPROC_HALFMATCH - FB_DATATYPE_STRUCT * FB_OVLPROC_CONVSCALE
16431643
end if
16441644
end if
16451645
#endmacro
@@ -1664,7 +1664,16 @@ end function
16641664
rec_cnt -= 1
16651665

16661666
if( proc <> NULL ) then
1667-
return FB_OVLPROC_HALFMATCH - FB_DATATYPE_STRUCT
1667+
'' calculate a new match score based on the CAST() return type rank
1668+
var match = typeCalcMatch( param_dtype, param_subtype, symbGetParamMode( param ), symbGetFullType( proc ), symbGetSubType( proc ) )
1669+
1670+
if( match >= FB_OVLPROC_TYPEMATCH ) then
1671+
return FB_OVLPROC_HALFMATCH - FB_DATATYPE_STRUCT * FB_OVLPROC_CONVSCALE + 2
1672+
elseif( match >= FB_OVLPROC_HALFMATCH ) then
1673+
return FB_OVLPROC_HALFMATCH - FB_DATATYPE_STRUCT * FB_OVLPROC_CONVSCALE + 1
1674+
end if
1675+
1676+
return FB_OVLPROC_HALFMATCH - FB_DATATYPE_STRUCT * FB_OVLPROC_CONVSCALE
16681677
end if
16691678
end if
16701679
#endmacro
@@ -1821,9 +1830,13 @@ private function hCalcTypesDiff _
18211830
'' corresponding to hStrArgToStrPtrParam())
18221831
case FB_DATACLASS_STRING
18231832
select case param_dtype
1824-
case FB_DATATYPE_CHAR, typeAddrOf( FB_DATATYPE_CHAR )
1833+
case FB_DATATYPE_CHAR
18251834
return FB_OVLPROC_FULLMATCH
1826-
case FB_DATATYPE_WCHAR, typeAddrOf( FB_DATATYPE_WCHAR )
1835+
case typeAddrOf( FB_DATATYPE_CHAR )
1836+
return FB_OVLPROC_FULLMATCH
1837+
case FB_DATATYPE_WCHAR
1838+
return FB_OVLPROC_HALFMATCH
1839+
case typeAddrOf( FB_DATATYPE_WCHAR )
18271840
return FB_OVLPROC_HALFMATCH
18281841
end select
18291842

src/compiler/symb.bi

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,10 @@ const FB_DT_MANGLEPOS = 20
7272
enum FB_OVLPROC_MATCH_SCORE
7373
FB_OVLPROC_NO_MATCH = 0
7474
FB_OVLPROC_LOWEST_MATCH = 1
75-
FB_OVLPROC_HALFMATCH = FB_DATATYPES
76-
FB_OVLPROC_TYPEMATCH = FB_DATATYPES * 2
77-
FB_OVLPROC_FULLMATCH = FB_DATATYPES * 3
75+
FB_OVLPROC_CONVSCALE = 2
76+
FB_OVLPROC_HALFMATCH = FB_DATATYPES * 1 * FB_OVLPROC_CONVSCALE
77+
FB_OVLPROC_TYPEMATCH = FB_DATATYPES * 2 * FB_OVLPROC_CONVSCALE
78+
FB_OVLPROC_FULLMATCH = FB_DATATYPES * 3 * FB_OVLPROC_CONVSCALE
7879
end enum
7980

8081
enum

tests/udt-zstring/left.bas

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ SUITE( fbc_tests.udt_zstring_.left_ )
2929
next
3030
#endmacro
3131

32+
#if ENABLE_CHECK_BUGS
33+
34+
'' left and right functions are not overloaded to accept a BYREF as ZSTRING
35+
3236
TEST( default )
3337

3438
check( "" )
@@ -37,4 +41,6 @@ SUITE( fbc_tests.udt_zstring_.left_ )
3741
check( "1234567890" )
3842
END_TEST
3943

44+
#endif
45+
4046
END_SUITE

0 commit comments

Comments
 (0)