This is an automated email from the git hooks/post-receive script.

git pushed a commit to branch eolian/improvements
in repository efl.

View the commit online.

commit c02d5663ec5ffded51e5ba337ae1d78d4c2953d5
Author: [email protected] <[email protected]>
AuthorDate: Thu Oct 29 22:47:06 2026 -0600

    eolian: a refused construct-only call returning Eina.Error gives EPERM
    
    With no default in the .eo, a construct-only function returning
    Eina.Error returned 0 when the guard refused the call, which callers
    read as success. It now returns EPERM, for aliases of Eina.Error too.
    An explicit default in the .eo still wins. This applies both to the
    refused path and to the unresolved one.
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
 doc/eolian/grammar.md                            |   6 +-
 src/bin/eolian/sources.c                         |  24 ++++-
 src/lib/eolian/Eolian.h                          |   3 +
 src/tests/eolian/data/construct_only_error.eo    |  44 ++++++++
 src/tests/eolian/data/construct_only_error_ref.c |  98 +++++++++++++++++
 src/tests/eolian/data/construct_only_error_ref.h | 128 +++++++++++++++++++++++
 src/tests/eolian/data/construct_only_types.eot   |   1 +
 src/tests/eolian/eolian_generation.c             |  10 ++
 8 files changed, 311 insertions(+), 3 deletions(-)

diff --git a/doc/eolian/grammar.md b/doc/eolian/grammar.md
index 65cfd3ccac..bd813f220e 100644
--- a/doc/eolian/grammar.md
+++ b/doc/eolian/grammar.md
@@ -277,8 +277,10 @@ Each qualifier may be given once.
 
 A refused call returns the default declared in the `.eo` file (`return: bool (false)`),
 exactly as a call that cannot be resolved does, so give a construct-only function a
-default that reads as failure. Setting the property through reflection returns
-`EPERM` instead.
+default that reads as failure. A function returning `Eina.Error` (or an alias of it)
+that declares no default returns `EPERM` instead of 0, both when the call is refused
+and when it cannot be resolved, as neither is a success; an explicit default always
+wins. Setting the property through reflection returns `EPERM` too.
 
 ## 5. Methods and properties
 
diff --git a/src/bin/eolian/sources.c b/src/bin/eolian/sources.c
index 8d9f480f67..8304eae1ec 100644
--- a/src/bin/eolian/sources.c
+++ b/src/bin/eolian/sources.c
@@ -103,6 +103,22 @@ _gen_func_pointer_param(const char *name, Eina_Stringshare *c_type,
    eina_strbuf_free(freename);
 }
 
+/* Whether a type is Eina.Error, or an alias of it however deep. */
+static Eina_Bool
+_type_is_eina_error(const Eolian_Type *tp)
+{
+   while (tp)
+     {
+        const Eolian_Typedecl *tdcl = eolian_type_typedecl_get(tp);
+        if (!tdcl || (eolian_typedecl_type_get(tdcl) != EOLIAN_TYPEDECL_ALIAS))
+          return EINA_FALSE;
+        if (eina_streq(eolian_typedecl_name_get(tdcl), "Eina.Error"))
+          return EINA_TRUE;
+        tp = eolian_typedecl_base_type_get(tdcl);
+     }
+   return EINA_FALSE;
+}
+
 static void
 _append_defval(Eina_Strbuf *buf, const Eolian_Expression *exp, const Eolian_Type *tp, const char *ctp)
 {
@@ -963,7 +979,13 @@ _gen_func(const Eolian_Class *cl, const Eolian_Function *fid,
         if (strcmp(rtpn, "void"))
           {
              eina_strbuf_append_printf(buf, ", %s, ", rtpn);
-             _append_defval(buf, def_ret, rtp, rtpn);
+             /* a refused construct only call must not read as success, and
+              * an error with no default of its own is 0, which does */
+             if (!def_ret && eolian_function_is_construct_only(fid, ftype)
+                 && _type_is_eina_error(rtp))
+               eina_strbuf_append(buf, "EPERM");
+             else
+               _append_defval(buf, def_ret, rtp, rtpn);
           }
 
         if (fallback_free_ownership)
diff --git a/src/lib/eolian/Eolian.h b/src/lib/eolian/Eolian.h
index 1512ccdda1..83d6d12b40 100644
--- a/src/lib/eolian/Eolian.h
+++ b/src/lib/eolian/Eolian.h
@@ -1733,6 +1733,9 @@ EOLIAN_API Eina_Bool eolian_function_is_constructor(const Eolian_Function *funct
  * A refused call to the generated C function returns the default value the
  * .eo declares for the function (as a call that cannot be resolved does), so
  * pick a default that reads as failure; the reflection setter returns EPERM.
+ * A function returning Eina.Error (or an alias of it) with no default of its
+ * own returns EPERM, for a refused call and for a call that cannot be
+ * resolved alike, as neither is a success. An explicit default always wins.
  *
  * @param[in] function_id Id of the function
  * @param[in] ftype which half of a property, or EOLIAN_METHOD
diff --git a/src/tests/eolian/data/construct_only_error.eo b/src/tests/eolian/data/construct_only_error.eo
new file mode 100644
index 0000000000..576ba7675a
--- /dev/null
+++ b/src/tests/eolian/data/construct_only_error.eo
@@ -0,0 +1,44 @@
+import construct_only_types;
+
+type Construct_Only_Status: Eina.Error; [[An alias of Eina.Error. @since 1.66]]
+
+class @beta Construct_Only_Error {
+   [[A class whose construct only functions return errors. @since 1.66]]
+   data: null;
+   methods {
+      apply {
+         [[Returns an error and declares no default: a refusal is EPERM.]]
+         return: Eina.Error; [[The error.]]
+      }
+      apply_alias {
+         [[Returns an alias of Eina.Error and declares no default: EPERM.]]
+         return: Construct_Only_Status; [[The error.]]
+      }
+      apply_default {
+         [[Returns an error with an explicit default, which wins.]]
+         return: Eina.Error (5); [[The error.]]
+      }
+      @property level {
+         [[A setter returning an error and declaring no default: EPERM.]]
+         set {
+            return: Eina.Error; [[The error.]]
+         }
+         get {
+         }
+         values {
+            level: int; [[The level.]]
+         }
+      }
+      apply_bool {
+         [[Not an error type, so the usual default.]]
+         return: bool; [[$true on success.]]
+      }
+   }
+   constructors {
+      .apply @construct_only @optional;
+      .apply_alias @construct_only @optional;
+      .apply_default @construct_only @optional;
+      .level @construct_only @optional;
+      .apply_bool @construct_only @optional;
+   }
+}
diff --git a/src/tests/eolian/data/construct_only_error_ref.c b/src/tests/eolian/data/construct_only_error_ref.c
new file mode 100644
index 0000000000..e15aab7bc6
--- /dev/null
+++ b/src/tests/eolian/data/construct_only_error_ref.c
@@ -0,0 +1,98 @@
+
+Eina_Error _construct_only_error_apply(Eo *obj, void *pd);
+
+EAPI EAPI_WEAK EFL_FUNC_BODY_CONSTRUCT_ONLY(construct_only_error_apply, Eina_Error, EPERM);
+
+Construct_Only_Status _construct_only_error_apply_alias(Eo *obj, void *pd);
+
+EAPI EAPI_WEAK EFL_FUNC_BODY_CONSTRUCT_ONLY(construct_only_error_apply_alias, Construct_Only_Status, EPERM);
+
+Eina_Error _construct_only_error_apply_default(Eo *obj, void *pd);
+
+EAPI EAPI_WEAK EFL_FUNC_BODY_CONSTRUCT_ONLY(construct_only_error_apply_default, Eina_Error, 5);
+
+Eina_Error _construct_only_error_level_set(Eo *obj, void *pd, int level);
+
+
+static Eina_Error
+__eolian_construct_only_error_level_set_reflect(Eo *obj, Eina_Value val)
+{
+   Eina_Error r = 0;   int cval;
+   if (efl_finalized_get(obj))
+      {
+         r = EPERM;
+         goto end;
+      }
+   if (!eina_value_int_convert(&val, &cval))
+      {
+         r = EINA_ERROR_VALUE_FAILED;
+         goto end;
+      }
+   construct_only_error_level_set(obj, cval);
+ end:
+   eina_value_flush(&val);
+   return r;
+}
+
+EAPI EAPI_WEAK EFL_FUNC_BODYV_CONSTRUCT_ONLY(construct_only_error_level_set, Eina_Error, EPERM, EFL_FUNC_CALL(level), int level);
+
+int _construct_only_error_level_get(const Eo *obj, void *pd);
+
+
+static Eina_Value
+__eolian_construct_only_error_level_get_reflect(const Eo *obj)
+{
+   int val = construct_only_error_level_get(obj);
+   return eina_value_int_init(val);
+}
+
+EAPI EAPI_WEAK EFL_FUNC_BODY_CONST(construct_only_error_level_get, int, 0);
+
+Eina_Bool _construct_only_error_apply_bool(Eo *obj, void *pd);
+
+EAPI EAPI_WEAK EFL_FUNC_BODY_CONSTRUCT_ONLY(construct_only_error_apply_bool, Eina_Bool, 0);
+
+static Eina_Bool
+_construct_only_error_class_initializer(Efl_Class *klass)
+{
+   const Efl_Object_Ops *opsp = NULL;
+
+   const Efl_Object_Property_Reflection_Ops *ropsp = NULL;
+
+#ifndef CONSTRUCT_ONLY_ERROR_EXTRA_OPS
+#define CONSTRUCT_ONLY_ERROR_EXTRA_OPS
+#endif
+
+   EFL_OPS_DEFINE(ops,
+      EFL_OBJECT_OP_FUNC(construct_only_error_apply, _construct_only_error_apply),
+      EFL_OBJECT_OP_FUNC(construct_only_error_apply_alias, _construct_only_error_apply_alias),
+      EFL_OBJECT_OP_FUNC(construct_only_error_apply_default, _construct_only_error_apply_default),
+      EFL_OBJECT_OP_FUNC(construct_only_error_level_set, _construct_only_error_level_set),
+      EFL_OBJECT_OP_FUNC(construct_only_error_level_get, _construct_only_error_level_get),
+      EFL_OBJECT_OP_FUNC(construct_only_error_apply_bool, _construct_only_error_apply_bool),
+      CONSTRUCT_ONLY_ERROR_EXTRA_OPS
+   );
+   opsp = &ops;
+
+   static const Efl_Object_Property_Reflection refl_table[] = {
+      {"level", __eolian_construct_only_error_level_set_reflect, __eolian_construct_only_error_level_get_reflect},
+   };
+   static const Efl_Object_Property_Reflection_Ops rops = {
+      refl_table, EINA_C_ARRAY_LENGTH(refl_table)
+   };
+   ropsp = &rops;
+
+   return efl_class_functions_set(klass, opsp, ropsp);
+}
+
+static const Efl_Class_Description _construct_only_error_class_desc = {
+   EO_VERSION,
+   "Construct_Only_Error",
+   EFL_CLASS_TYPE_REGULAR,
+   0,
+   _construct_only_error_class_initializer,
+   NULL,
+   NULL
+};
+
+EFL_DEFINE_CLASS(construct_only_error_class_get, &_construct_only_error_class_desc, NULL, NULL);
diff --git a/src/tests/eolian/data/construct_only_error_ref.h b/src/tests/eolian/data/construct_only_error_ref.h
new file mode 100644
index 0000000000..414fcdaeed
--- /dev/null
+++ b/src/tests/eolian/data/construct_only_error_ref.h
@@ -0,0 +1,128 @@
+#ifndef _EOLIAN_CONSTRUCT_ONLY_ERROR_EO_H_
+#define _EOLIAN_CONSTRUCT_ONLY_ERROR_EO_H_
+
+#ifndef _CONSTRUCT_ONLY_ERROR_EO_CLASS_TYPE
+#define _CONSTRUCT_ONLY_ERROR_EO_CLASS_TYPE
+
+#ifndef _CONSTRUCT_ONLY_ERROR_EO_CLASS_TYPE_FWD
+#define _CONSTRUCT_ONLY_ERROR_EO_CLASS_TYPE_FWD
+typedef Eo Construct_Only_Error;
+#endif
+
+#endif
+
+#ifndef _CONSTRUCT_ONLY_ERROR_EO_TYPES
+#define _CONSTRUCT_ONLY_ERROR_EO_TYPES
+
+/** An alias of Eina.Error.
+ *
+ * @since 1.66
+ *
+ * @ingroup Construct_Only_Status
+ */
+typedef Eina_Error Construct_Only_Status;
+
+
+#endif
+#ifdef EFL_BETA_API_SUPPORT
+/** A class whose construct only functions return errors.
+ *
+ * @since 1.66
+ *
+ * @ingroup Construct_Only_Error
+ */
+#define CONSTRUCT_ONLY_ERROR_CLASS construct_only_error_class_get()
+
+EAPI EAPI_WEAK const Efl_Class *construct_only_error_class_get(void) EINA_CONST;
+
+/**
+ * @brief Returns an error and declares no default: a refusal is EPERM.
+ *
+ * @note This function is only allowed during construction, inside efl_add and before the object is finalized.
+ *
+ * @param[in] obj The object.
+ *
+ * @return The error.
+ *
+ * @since 1.66
+ *
+ * @ingroup Construct_Only_Error
+ */
+EAPI EAPI_WEAK Eina_Error construct_only_error_apply(Eo *obj);
+
+/**
+ * @brief Returns an alias of Eina.Error and declares no default: EPERM.
+ *
+ * @note This function is only allowed during construction, inside efl_add and before the object is finalized.
+ *
+ * @param[in] obj The object.
+ *
+ * @return The error.
+ *
+ * @since 1.66
+ *
+ * @ingroup Construct_Only_Error
+ */
+EAPI EAPI_WEAK Construct_Only_Status construct_only_error_apply_alias(Eo *obj);
+
+/**
+ * @brief Returns an error with an explicit default, which wins.
+ *
+ * @note This function is only allowed during construction, inside efl_add and before the object is finalized.
+ *
+ * @param[in] obj The object.
+ *
+ * @return The error.
+ *
+ * @since 1.66
+ *
+ * @ingroup Construct_Only_Error
+ */
+EAPI EAPI_WEAK Eina_Error construct_only_error_apply_default(Eo *obj);
+
+/**
+ * @brief A setter returning an error and declaring no default: EPERM.
+ *
+ * @note This function is only allowed during construction, inside efl_add and before the object is finalized.
+ *
+ * @param[in] obj The object.
+ * @param[in] level The level.
+ *
+ * @return The error.
+ *
+ * @since 1.66
+ *
+ * @ingroup Construct_Only_Error
+ */
+EAPI EAPI_WEAK Eina_Error construct_only_error_level_set(Eo *obj, int level);
+
+/**
+ * @brief A setter returning an error and declaring no default: EPERM.
+ *
+ * @param[in] obj The object.
+ *
+ * @return The level.
+ *
+ * @since 1.66
+ *
+ * @ingroup Construct_Only_Error
+ */
+EAPI EAPI_WEAK int construct_only_error_level_get(const Eo *obj);
+
+/**
+ * @brief Not an error type, so the usual default.
+ *
+ * @note This function is only allowed during construction, inside efl_add and before the object is finalized.
+ *
+ * @param[in] obj The object.
+ *
+ * @return @c true on success.
+ *
+ * @since 1.66
+ *
+ * @ingroup Construct_Only_Error
+ */
+EAPI EAPI_WEAK Eina_Bool construct_only_error_apply_bool(Eo *obj);
+#endif /* EFL_BETA_API_SUPPORT */
+
+#endif
diff --git a/src/tests/eolian/data/construct_only_types.eot b/src/tests/eolian/data/construct_only_types.eot
new file mode 100644
index 0000000000..12aece6a88
--- /dev/null
+++ b/src/tests/eolian/data/construct_only_types.eot
@@ -0,0 +1 @@
+type @extern Eina.Error: int; [[A stand-in for the Eina.Error of eina_types.eot, which the generation tests do not load. @since 1.66]]
diff --git a/src/tests/eolian/eolian_generation.c b/src/tests/eolian/eolian_generation.c
index 73f557d327..74accd58c8 100644
--- a/src/tests/eolian/eolian_generation.c
+++ b/src/tests/eolian/eolian_generation.c
@@ -169,6 +169,16 @@ EFL_START_TEST(eolian_construct_only_generation)
    fail_if(0 != _eolian_gen_execute(TESTS_SRC_DIR"/data/construct_only.eo", "-gh", output_filepath));
    fail_if(!_files_compare(TESTS_SRC_DIR"/data/construct_only_ref.h", output_filepath, "eo.h"));
 
+   /* a refused Eina.Error (or alias of it) is EPERM unless the .eo says otherwise */
+   snprintf(output_filepath, PATH_MAX, "%s/eolian_construct_only_error",
+            eina_environment_tmp_get());
+   _remove_ref(output_filepath, "eo.c");
+   _remove_ref(output_filepath, "eo.h");
+   fail_if(0 != _eolian_gen_execute(TESTS_SRC_DIR"/data/construct_only_error.eo", "-gc", output_filepath));
+   fail_if(!_files_compare(TESTS_SRC_DIR"/data/construct_only_error_ref.c", output_filepath, "eo.c"));
+   fail_if(0 != _eolian_gen_execute(TESTS_SRC_DIR"/data/construct_only_error.eo", "-gh", output_filepath));
+   fail_if(!_files_compare(TESTS_SRC_DIR"/data/construct_only_error_ref.h", output_filepath, "eo.h"));
+
    /* inherited restriction is the parent's own, only the new one is guarded */
    snprintf(output_filepath, PATH_MAX, "%s/eolian_construct_only_child",
             eina_environment_tmp_get());

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.

Reply via email to