From 5a680f014892d09c531e93ff6c058731f803b84c Mon Sep 17 00:00:00 2001 From: Sven/Sarah Barth Date: Mon, 30 May 2022 23:05:45 +0200 Subject: [PATCH] * fix #39745: the conversion from ordinals to pointer types in mode Delphi is not allowed for a void type (happens when using a typecast to convert a method without parameters to a function reference) + added test --- compiler/defcmp.pas | 5 ++++- tests/webtbs/tw39745.pp | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 tests/webtbs/tw39745.pp diff --git a/compiler/defcmp.pas b/compiler/defcmp.pas index 04d5af3d75..5451a3b8f6 100644 --- a/compiler/defcmp.pas +++ b/compiler/defcmp.pas @@ -1988,7 +1988,10 @@ implementation } else if (not(target_info.system in systems_jvm) and ((def_from.typ=enumdef) or - (def_from.typ=orddef))) and + ( + (def_from.typ=orddef) and + not is_void(def_from) + ))) and (m_delphi in current_settings.modeswitches) and (cdo_explicit in cdoptions) then begin diff --git a/tests/webtbs/tw39745.pp b/tests/webtbs/tw39745.pp new file mode 100644 index 0000000000..23689929b1 --- /dev/null +++ b/tests/webtbs/tw39745.pp @@ -0,0 +1,39 @@ +{ %NORUN } + +program tw39745; + +{$mode delphi} // objfpc is ok +{$modeswitch functionreferences} +//uses classes; +type + TThreadMethod = procedure of object; + TThreadProcedure = reference to procedure; + + TThread = class + procedure Queue(aMethod: TThreadMethod);overload; + procedure Queue(aFuncRef: TThreadProcedure);overload; + end; + + TTestThread = class(tthread) + + procedure something; // matches tthreadmethod + procedure xx; + end; + +procedure tthread.Queue(aMethod: TThreadMethod); +begin +end; +procedure tthread.Queue(aFuncRef: TThreadProcedure); +begin +end; +procedure ttestthread.something; +begin +end; +procedure ttestthread.xx; +begin + Queue(tthreadprocedure(Something)); // add @ for mode objfpc +end; + +begin +end. +