[vala/staging] vala: Support static methods in error-domains
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/staging] vala: Support static methods in error-domains
- Date: Tue, 30 Jul 2019 12:32:26 +0000 (UTC)
commit 1d0f812ed79eb866b9221975a2eb4b78e04761cf
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Sun Jul 28 17:21:25 2019 +0200
vala: Support static methods in error-domains
Actually generate methods defined inside error-domains and state that
instance methods are not supported yet.
See https://gitlab.gnome.org/GNOME/vala/issues/829
codegen/valagerrormodule.vala | 2 ++
tests/Makefile.am | 2 ++
tests/errors/errordomain-instance-method.test | 11 +++++++++
tests/errors/errordomain-static-method.vala | 13 ++++++++++
vala/valaerrordomain.vala | 4 ++++
valadoc/tests/drivers/api-test.data.vapi | 1 -
valadoc/tests/drivers/generic-api-test.vala | 34 +--------------------------
7 files changed, 33 insertions(+), 34 deletions(-)
---
diff --git a/codegen/valagerrormodule.vala b/codegen/valagerrormodule.vala
index bae957f02..2abd5a4ce 100644
--- a/codegen/valagerrormodule.vala
+++ b/codegen/valagerrormodule.vala
@@ -59,6 +59,8 @@ public class Vala.GErrorModule : CCodeDelegateModule {
}
public override void visit_error_domain (ErrorDomain edomain) {
+ edomain.accept_children (this);
+
if (edomain.comment != null) {
cfile.add_type_definition (new CCodeComment (edomain.comment.content));
}
diff --git a/tests/Makefile.am b/tests/Makefile.am
index f1b9be8fe..cada29aa2 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -414,6 +414,8 @@ TESTS = \
errors/errors.vala \
errors/errorcode.vala \
errors/errordomain.vala \
+ errors/errordomain-instance-method.test \
+ errors/errordomain-static-method.vala \
errors/invalid-type-check.test \
errors/method-throws.vala \
errors/bug567181.vala \
diff --git a/tests/errors/errordomain-instance-method.test b/tests/errors/errordomain-instance-method.test
new file mode 100644
index 000000000..49c80967b
--- /dev/null
+++ b/tests/errors/errordomain-instance-method.test
@@ -0,0 +1,11 @@
+Invalid Code
+
+errordomain Foo {
+ BAD;
+
+ public void bar () {
+ }
+}
+
+void main () {
+}
diff --git a/tests/errors/errordomain-static-method.vala b/tests/errors/errordomain-static-method.vala
new file mode 100644
index 000000000..871a5e6ad
--- /dev/null
+++ b/tests/errors/errordomain-static-method.vala
@@ -0,0 +1,13 @@
+errordomain Foo {
+ BAD = 23;
+
+ public static Foo from_string (string error) {
+ assert (error == "BAD");
+ return new Foo.BAD ("BAD");
+ }
+}
+
+void main () {
+ var e = Foo.from_string ("BAD");
+ assert (e.code == Foo.BAD);
+}
diff --git a/vala/valaerrordomain.vala b/vala/valaerrordomain.vala
index c0e92e70e..8e35caa24 100644
--- a/vala/valaerrordomain.vala
+++ b/vala/valaerrordomain.vala
@@ -125,6 +125,10 @@ public class Vala.ErrorDomain : TypeSymbol {
}
foreach (Method m in methods) {
+ if (m.binding == MemberBinding.INSTANCE) {
+ Report.error (m.source_reference, "Instance methods are not supported in
error domain `%s'".printf (get_full_name ()));
+ error = true;
+ }
m.check (context);
}
diff --git a/valadoc/tests/drivers/api-test.data.vapi b/valadoc/tests/drivers/api-test.data.vapi
index 788a6bab6..37871f012 100644
--- a/valadoc/tests/drivers/api-test.data.vapi
+++ b/valadoc/tests/drivers/api-test.data.vapi
@@ -25,7 +25,6 @@ public errordomain TestErrDomGlobal {
ERROR1,
ERROR2;
- public void method ();
public static void static_method ();
}
diff --git a/valadoc/tests/drivers/generic-api-test.vala b/valadoc/tests/drivers/generic-api-test.vala
index 94f572cfd..5d20405d6 100644
--- a/valadoc/tests/drivers/generic-api-test.vala
+++ b/valadoc/tests/drivers/generic-api-test.vala
@@ -257,44 +257,12 @@ public static void test_erroromain_global (Api.ErrorDomain? err, Api.Package pkg
assert (errc2 == true);
-
- Vala.List<Api.Node> methods = err.get_children_by_type (Api.NodeType.METHOD, false);
+ Vala.List<Api.Node> methods = err.get_children_by_type (Api.NodeType.STATIC_METHOD, false);
assert (methods.size == 1);
Api.Method method = methods.get (0) as Api.Method;
assert (method != null);
- // (.Method check)
- assert (method.get_cname () == "test_err_dom_global_method");
- //assert (method.get_dbus_name () == null);
- //assert (method.get_dbus_result_name () == null);
- //assert (method.is_dbus_visible == false);
- assert (method.base_method == null);
- assert (method.is_yields == false);
- assert (method.is_abstract == false);
- assert (method.is_virtual == false);
- assert (method.is_override == false);
- assert (method.is_static == false);
- assert (method.is_constructor == false);
- assert (method.is_inline == false);
- // (.Symbol check)
- assert (method.is_deprecated == false);
- assert (method.accessibility == Vala.SymbolAccessibility.PUBLIC);
- // (.Node)
- assert (method.get_full_name () == "TestErrDomGlobal.method");
- assert (method.get_filename () == "api-test.data.vapi");
- assert (method.name == "method");
- assert (method.nspace == global_ns);
- assert (method.package == pkg);
-
-
-
- methods = err.get_children_by_type (Api.NodeType.STATIC_METHOD, false);
- assert (methods.size == 1);
-
- method = methods.get (0) as Api.Method;
- assert (method != null);
-
// (.Method check)
assert (method.get_cname () == "test_err_dom_global_static_method");
//assert (method.get_dbus_name () == null);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]