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



commit 988e77e02104f71fda5190de7e509f0ceca2283a
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 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;
                        }
                }
 


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