patch 8.2.2743: Vim9: function state stuck when compiling with ":silent!"

Problem:    Vim9: function state stuck when compiling with ":silent!".
Solution:   Check for uf_def_status to be UF_COMPILING.
diff --git a/src/globals.h b/src/globals.h
index 94ec54b..51a6946 100644
--- a/src/globals.h
+++ b/src/globals.h
@@ -230,6 +230,9 @@
 EXTERN int	did_emsg;		    // set by emsg() when the message
 					    // is displayed or thrown
 #ifdef FEAT_EVAL
+EXTERN int	did_emsg_silent INIT(= 0);  // incremented by emsg() when
+					    // emsg_silent was set and did_emsg
+					    // is not incremented
 EXTERN int	did_emsg_def;		    // set by emsg() when emsg_silent
 					    // is set before calling a function
 EXTERN int	did_emsg_cumul;		    // cumulative did_emsg, increased
diff --git a/src/message.c b/src/message.c
index 07c3943..f2fe23b 100644
--- a/src/message.c
+++ b/src/message.c
@@ -685,6 +685,9 @@
 	 */
 	if (emsg_silent != 0)
 	{
+#ifdef FEAT_EVAL
+	    ++did_emsg_silent;
+#endif
 	    if (emsg_noredir == 0)
 	    {
 		msg_start();
diff --git a/src/testdir/test_vim9_func.vim b/src/testdir/test_vim9_func.vim
index 6a3dfbb..e254f44 100644
--- a/src/testdir/test_vim9_func.vim
+++ b/src/testdir/test_vim9_func.vim
@@ -2603,6 +2603,20 @@
 
   # Second call won't try compiling again
   assert_fails('call g:Broken()', 'E1091: Function is not compiled: Broken')
+  delfunc g:Broken
+
+  # No error when compiling with :silent!
+  lines =<< trim END
+    def g:Broken()
+      echo 'a' + []
+    enddef
+    silent! defcompile
+  END
+  CheckScriptSuccess(lines)
+
+  # Calling the function won't try compiling again
+  assert_fails('call g:Broken()', 'E1091: Function is not compiled: Broken')
+  delfunc g:Broken
 enddef
 
 
diff --git a/src/version.c b/src/version.c
index 5cf56fe..a22312a 100644
--- a/src/version.c
+++ b/src/version.c
@@ -751,6 +751,8 @@
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    2743,
+/**/
     2742,
 /**/
     2741,
diff --git a/src/vim9compile.c b/src/vim9compile.c
index aa5894a..e5e3068 100644
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -8429,6 +8429,7 @@
     cctx_T	cctx;
     garray_T	*instr;
     int		did_emsg_before = did_emsg;
+    int		did_emsg_silent_before = did_emsg_silent;
     int		ret = FAIL;
     sctx_T	save_current_sctx = current_sctx;
     int		save_estack_compiling = estack_compiling;
@@ -8967,6 +8968,9 @@
 	generate_instr(&cctx, ISN_RETURN_ZERO);
     }
 
+    // When compiled with ":silent!" and there was an error don't consider the
+    // function compiled.
+    if (emsg_silent == 0 || did_emsg_silent == did_emsg_silent_before)
     {
 	dfunc_T	*dfunc = ((dfunc_T *)def_functions.ga_data)
 							 + ufunc->uf_dfunc_idx;
@@ -8994,7 +8998,7 @@
     ret = OK;
 
 erret:
-    if (ret == FAIL)
+    if (ufunc->uf_def_status == UF_COMPILING)
     {
 	int idx;
 	dfunc_T	*dfunc = ((dfunc_T *)def_functions.ga_data)