summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRico Tzschichholz <ricotz@ubuntu.com>2019-11-03 20:03:20 +0100
committerRico Tzschichholz <ricotz@ubuntu.com>2019-11-03 20:10:26 +0100
commit988e77e02104f71fda5190de7e509f0ceca2283a (patch)
treeaaaa74d25505414312688538182e3e57f26f9235
parent8e908c01a0f2ba6863f130ea3a223af41b54eaab (diff)
downloadvala-988e77e02104f71fda5190de7e509f0ceca2283a.tar.gz
vala: Improve error reporting for invalid interface prerequisites
Fixes https://gitlab.gnome.org/GNOME/vala/issues/437
-rw-r--r--tests/Makefile.am2
-rw-r--r--tests/semantic/interface-prerequisite-invalid.test11
-rw-r--r--tests/semantic/interface-prerequisite-less-accessible.test10
-rw-r--r--vala/valainterface.vala17
4 files changed, 28 insertions, 12 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 292eea0c7..5794aa162 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -709,6 +709,8 @@ TESTS = \
semantic/foreach-next-void.test \
semantic/foreach-wrong-types.test \
semantic/initializer-unknown-type.test \
+ semantic/interface-prerequisite-invalid.test \
+ semantic/interface-prerequisite-less-accessible.test \
semantic/localvariable-owned-to-unowned.test \
semantic/localvariable-var-static-access-instance-field.test \
semantic/localvariable-var-static-access-instance-method.test \
diff --git a/tests/semantic/interface-prerequisite-invalid.test b/tests/semantic/interface-prerequisite-invalid.test
new file mode 100644
index 000000000..304e27902
--- /dev/null
+++ b/tests/semantic/interface-prerequisite-invalid.test
@@ -0,0 +1,11 @@
+Invalid Code
+
+struct Bar {
+ public int i;
+}
+
+interface Foo : Bar {
+}
+
+void main () {
+}
diff --git a/tests/semantic/interface-prerequisite-less-accessible.test b/tests/semantic/interface-prerequisite-less-accessible.test
new file mode 100644
index 000000000..3855ea47f
--- /dev/null
+++ b/tests/semantic/interface-prerequisite-less-accessible.test
@@ -0,0 +1,10 @@
+Invalid Code
+
+class Bar {
+}
+
+public interface Foo : Bar {
+}
+
+void main () {
+}
diff --git a/vala/valainterface.vala b/vala/valainterface.vala
index 44613f9ef..eb63e9a05 100644
--- a/vala/valainterface.vala
+++ b/vala/valainterface.vala
@@ -176,28 +176,21 @@ public class Vala.Interface : ObjectTypeSymbol {
/* check prerequisites */
Class prereq_class = null;
foreach (DataType prereq in get_prerequisites ()) {
- TypeSymbol class_or_interface = prereq.type_symbol;
- /* skip on previous errors */
- if (class_or_interface == null) {
+ if (!(prereq is ObjectType)) {
error = true;
- continue;
- }
-
- if (!(class_or_interface is ObjectTypeSymbol)) {
- error = true;
- Report.error (source_reference, "Prerequisite `%s' of interface `%s' is not a class or interface".printf (get_full_name (), class_or_interface.to_string ()));
+ Report.error (source_reference, "Prerequisite `%s' of interface `%s' is not a class or interface".printf (prereq.to_string (), get_full_name ()));
return false;
}
/* interfaces are not allowed to have multiple instantiable prerequisites */
- if (class_or_interface is Class) {
+ if (prereq.type_symbol is Class) {
if (prereq_class != null) {
error = true;
- Report.error (source_reference, "%s: Interfaces cannot have multiple instantiable prerequisites (`%s' and `%s')".printf (get_full_name (), class_or_interface.get_full_name (), prereq_class.get_full_name ()));
+ Report.error (source_reference, "%s: Interfaces cannot have multiple instantiable prerequisites (`%s' and `%s')".printf (get_full_name (), prereq.type_symbol.get_full_name (), prereq_class.get_full_name ()));
return false;
}
- prereq_class = (Class) class_or_interface;
+ prereq_class = (Class) prereq.type_symbol;
}
}