Skip to content

Commit be20f5b

Browse files
committed
parser: Show error instead of warning for byref function without result
This fixes #755. Of course the check is simple and won't catch all possible cases - it only checks whether the function result was set once, but it does not check whether it was set on all code paths.
1 parent 51461d1 commit be20f5b

File tree

5 files changed

+13
-2
lines changed

5 files changed

+13
-2
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ Version 1.01.0
6464
- When passing a constant zero of some integer to an overloaded procedure, overloads with integer parameters will now be preferred over overloads with pointers (literal 0 can still be passed to pointer parameters in this case though, by casting it to the pointer type)
6565
- Literal zeroes with [U]Byte or [U]Short type (or the 16bit Integer in -lang qb) can now be passed to pointer parameters of overloaded procedures (now it's possible to call Bsave() with 0 source buffer in -lang qb again -- it also was affected by this bug since FB 0.90)
6666
- #760: RETURN and FUNCTION= couldn't be used together in byref functions returning an UDT with constructor. This check is now only applied to functions returning byval.
67+
- #755: If no result is set in byref functions, the compiler will now show an error instead of a warning (because a byref function defaults to returning a null reference, most likely causing a crash at runtime)
6768

6869

6970
Version 1.00.0 (former 0.91.0):

src/compiler/error.bas

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,8 @@ declare function hMakeParamDesc _
395395
@"vararg parameters are only allowed in CDECL procedures", _
396396
@"the first parameter in a procedure may not be vararg", _
397397
@"CONST used on constructor (not needed)", _
398-
@"CONST used on destructor (not needed)" _
398+
@"CONST used on destructor (not needed)", _
399+
@"Byref function result not set" _
399400
}
400401

401402

src/compiler/error.bi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ enum FB_ERRMSG
317317
FB_ERRMSG_VARARGNOTALLOWEDASFIRSTPARAM
318318
FB_ERRMSG_CONSTCTOR
319319
FB_ERRMSG_CONSTDTOR
320+
FB_ERRMSG_NOBYREFFUNCTIONRESULT
320321

321322
FB_ERRMSGS
322323
end enum

src/compiler/parser-proc.bas

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1818,7 +1818,11 @@ sub cProcStmtEnd( )
18181818
if( proc_res <> NULL ) then
18191819
if( symbGetIsAccessed( proc_res ) = FALSE ) then
18201820
if( symbIsNaked( parser.currproc ) = FALSE ) then
1821-
errReportWarn( FB_WARNINGMSG_NOFUNCTIONRESULT )
1821+
if( symbProcReturnsByref( parser.currproc ) ) then
1822+
errReport( FB_ERRMSG_NOBYREFFUNCTIONRESULT )
1823+
else
1824+
errReportWarn( FB_WARNINGMSG_NOFUNCTIONRESULT )
1825+
end if
18221826
end if
18231827
end if
18241828
end if
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
' TEST_MODE : COMPILE_ONLY_FAIL
2+
3+
function f( ) byref as integer
4+
end function

0 commit comments

Comments
 (0)