Skip to content

Commit

Permalink
vala: Don't allow inheritance of compact class from non-compact class
Browse files Browse the repository at this point in the history
  • Loading branch information
ricotz committed Apr 22, 2024
1 parent 5f9ae5e commit 040646d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -1142,6 +1142,7 @@ TESTS = \
semantic/class-compact-field-lock.test \
semantic/class-compact-field-private.test \
semantic/class-compact-derived-instance-field.test \
semantic/class-compact-inheritance.test \
semantic/class-compact-interface.test \
semantic/class-compact-method-baseaccess.test \
semantic/class-compact-property-baseaccess.test \
Expand Down
11 changes: 11 additions & 0 deletions tests/semantic/class-compact-inheritance.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Invalid Code

class Foo {
}

[Compact]
class Bar : Foo {
}

void main () {
}
6 changes: 6 additions & 0 deletions vala/valaclass.vala
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,12 @@ public class Vala.Class : ObjectTypeSymbol {
}
}

if (base_class != null && !base_class.is_compact && has_attribute ("Compact")) {
error = true;
Report.error (source_reference, "Compact class `%s' cannot inherit from non-compact class `%s'", get_full_name (), base_class.get_full_name ());
return false;
}

/* process enums first to avoid order problems in C code */
foreach (Enum en in get_enums ()) {
en.check (context);
Expand Down

0 comments on commit 040646d

Please sign in to comment.