[vala/0.46] vala: Improve error reporting for invalid interface prerequisites



commit ae1da75ada18fd8b2c8b1f15476d2e22bfb130cc
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Sun Nov 3 20:03:20 2019 +0100

    vala: Improve error reporting for invalid interface prerequisites
    
    Fixes https://gitlab.gnome.org/GNOME/vala/issues/437

 tests/Makefile.am                                       |  2 ++
 tests/semantic/interface-prerequisite-invalid.test      | 11 +++++++++++
 .../interface-prerequisite-less-accessible.test         | 10 ++++++++++
 vala/valainterface.vala                                 | 17 +++++------------
 4 files changed, 28 insertions(+), 12 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 5ebbd0389..29768848e 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -702,6 +702,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 f6c503641..3a3a28cad 100644
--- a/vala/valainterface.vala
+++ b/vala/valainterface.vala
@@ -214,28 +214,21 @@ public class Vala.Interface : ObjectTypeSymbol {
                /* check prerequisites */
                Class prereq_class = null;
                foreach (DataType prereq in get_prerequisites ()) {
-                       TypeSymbol class_or_interface = prereq.data_type;
-                       /* 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.data_type 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.data_type.get_full_name (), 
prereq_class.get_full_name ()));
                                        return false;
                                }
 
-                               prereq_class = (Class) class_or_interface;
+                               prereq_class = (Class) prereq.data_type;
                        }
                }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]