From: Rico Tzschichholz Date: Sun, 8 Jul 2018 15:52:50 +0000 (+0200) Subject: vala: Report error for invalid base access in method/property of compact class X-Git-Tag: 0.41.90~29 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fkeep-around%2F84de99560ee96afa8cb80db3b342d584a72188cd;p=thirdparty%2Fvala.git vala: Report error for invalid base access in method/property of compact class --- diff --git a/tests/Makefile.am b/tests/Makefile.am index 879f606ea..4734429c9 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -481,6 +481,8 @@ TESTS = \ semantic/class-base-type-less-accessible.test \ semantic/class-compact-derived-instance-field.test \ semantic/class-compact-interface.test \ + semantic/class-compact-method-baseaccess.test + semantic/class-compact-property-baseaccess.test semantic/class-missing-implement-interface-method.test \ semantic/class-missing-implement-interface-property.test \ semantic/class-missing-implement-method.test \ diff --git a/tests/semantic/class-compact-method-baseaccess.test b/tests/semantic/class-compact-method-baseaccess.test new file mode 100644 index 000000000..600eda89e --- /dev/null +++ b/tests/semantic/class-compact-method-baseaccess.test @@ -0,0 +1,17 @@ +Invalid Code + +[Compact] +public class Foo { + public virtual void bar () { + } +} + +[Compact] +public class Bar : Foo { + public override void bar () { + base (); + } +} + +void main () { +} diff --git a/tests/semantic/class-compact-property-baseaccess.test b/tests/semantic/class-compact-property-baseaccess.test new file mode 100644 index 000000000..967baf343 --- /dev/null +++ b/tests/semantic/class-compact-property-baseaccess.test @@ -0,0 +1,19 @@ +Invalid Code + +[Compact] +public class Foo { + public int field = 23; + public virtual int prop { + get { return field; } + } +} + +[Compact] +public class Bar : Foo { + public override int prop { + get { return base.prop; } + } +} + +void main () { +} diff --git a/vala/valabaseaccess.vala b/vala/valabaseaccess.vala index 7631f9e79..955233bdc 100644 --- a/vala/valabaseaccess.vala +++ b/vala/valabaseaccess.vala @@ -77,6 +77,15 @@ public class Vala.BaseAccess : Expression { error = true; Report.error (source_reference, "Base access invalid without base class"); return false; + } else if (context.analyzer.current_class.is_compact && context.analyzer.current_method != null + && !(context.analyzer.current_method is CreationMethod)) { + error = true; + Report.error (source_reference, "Base access invalid in virtual overridden method of compact class"); + return false; + } else if (context.analyzer.current_class.is_compact && context.analyzer.current_property_accessor != null) { + error = true; + Report.error (source_reference, "Base access invalid in virtual overridden property of compact class"); + return false; } else { foreach (var base_type in context.analyzer.current_class.get_base_types ()) { if (base_type.data_type is Class) {