[vala/0.40] vala: Allow direct access to the integer constants of an error-domain
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/0.40] vala: Allow direct access to the integer constants of an error-domain
- Date: Wed, 9 Oct 2019 17:32:09 +0000 (UTC)
commit 9faabc2afad29f6d4283e90ce576bc7ad13a5bdd
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Sat Jan 12 15:20:34 2019 +0100
vala: Allow direct access to the integer constants of an error-domain
Fixes https://gitlab.gnome.org/GNOME/vala/issues/732
tests/Makefile.am | 1 +
tests/errors/errorcode.vala | 32 ++++++++++++++++++++++++++++++++
vala/valaerrorcode.vala | 20 ++++++++++++++++++++
vala/valamemberaccess.vala | 3 +++
4 files changed, 56 insertions(+)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 69198df77..09aa60fa7 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -367,6 +367,7 @@ TESTS = \
errors/catch-error-code.vala \
errors/catch-in-finally.vala \
errors/errors.vala \
+ errors/errorcode.vala \
errors/invalid-type-check.test \
errors/bug567181.vala \
errors/bug579101.vala \
diff --git a/tests/errors/errorcode.vala b/tests/errors/errorcode.vala
new file mode 100644
index 000000000..2cb96ec67
--- /dev/null
+++ b/tests/errors/errorcode.vala
@@ -0,0 +1,32 @@
+errordomain FooError {
+ REALLY_BAD,
+ NOT_SO_GOOD,
+ EVEN_WORSE = 23
+}
+
+void main () {
+ {
+ var error = new IOError.NO_SPACE ("foo");
+ assert (error.code == 12);
+ }
+ {
+ var code = IOError.NO_SPACE;
+ assert (code == 12);
+ }
+ {
+ var error = new FooError.NOT_SO_GOOD ("foo");
+ assert (error.code == 1);
+ }
+ {
+ var code = FooError.NOT_SO_GOOD;
+ assert (code == 1);
+ }
+ {
+ var error = new FooError.EVEN_WORSE ("foo");
+ assert (error.code == 23);
+ }
+ {
+ var code = FooError.EVEN_WORSE;
+ assert (code == 23);
+ }
+}
diff --git a/vala/valaerrorcode.vala b/vala/valaerrorcode.vala
index 62ff540e0..c03b2577a 100644
--- a/vala/valaerrorcode.vala
+++ b/vala/valaerrorcode.vala
@@ -39,7 +39,23 @@ public class Vala.ErrorCode : TypeSymbol {
}
}
+ /**
+ * Refers to the enum value of this error code for direct access.
+ */
+ public Constant code {
+ get {
+ return _code;
+ }
+ private set {
+ _code = value;
+ if (_code != null) {
+ _code.owner = owner;
+ }
+ }
+ }
+
private Expression _value;
+ private Constant _code;
/**
* Creates a new enum value.
@@ -84,6 +100,10 @@ public class Vala.ErrorCode : TypeSymbol {
value.check (context);
}
+ code = new Constant (name, context.analyzer.int_type.copy (), null, source_reference,
comment);
+ code.external = true;
+ code.check (context);
+
return !error;
}
}
diff --git a/vala/valamemberaccess.vala b/vala/valamemberaccess.vala
index 6e1fb3bc0..ef81c3cde 100644
--- a/vala/valamemberaccess.vala
+++ b/vala/valamemberaccess.vala
@@ -706,6 +706,9 @@ public class Vala.MemberAccess : Expression {
} else if (member is Signal) {
instance = true;
access = member.access;
+ } else if (!creation_member && member is ErrorCode) {
+ symbol_reference = ((ErrorCode) member).code;
+ member = symbol_reference;
}
member.used = true;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]