Skip to content

Commit

Permalink
vala: Improve error reporting for invalid interface prerequisites
Browse files Browse the repository at this point in the history
  • Loading branch information
ricotz committed Nov 4, 2019
1 parent d609a5b commit ae1da75
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 12 deletions.
2 changes: 2 additions & 0 deletions tests/Makefile.am
Expand Up @@ -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 \
Expand Down
11 changes: 11 additions & 0 deletions tests/semantic/interface-prerequisite-invalid.test
@@ -0,0 +1,11 @@
Invalid Code

struct Bar {
public int i;
}

interface Foo : Bar {
}

void main () {
}
10 changes: 10 additions & 0 deletions tests/semantic/interface-prerequisite-less-accessible.test
@@ -0,0 +1,10 @@
Invalid Code

class Bar {
}

public interface Foo : Bar {
}

void main () {
}
17 changes: 5 additions & 12 deletions vala/valainterface.vala
Expand Up @@ -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;
}
}

Expand Down

0 comments on commit ae1da75

Please sign in to comment.