]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
vala: Report error for invalid base access in method/property of compact class 84de99560ee96afa8cb80db3b342d584a72188cd
authorRico Tzschichholz <ricotz@ubuntu.com>
Sun, 8 Jul 2018 15:52:50 +0000 (17:52 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Sun, 8 Jul 2018 15:55:23 +0000 (17:55 +0200)
tests/Makefile.am
tests/semantic/class-compact-method-baseaccess.test [new file with mode: 0644]
tests/semantic/class-compact-property-baseaccess.test [new file with mode: 0644]
vala/valabaseaccess.vala

index 879f606eae143dfbcdf77cf9ce71f56b99e0ca15..4734429c97765a23e58d2443d60e16b074faa4f0 100644 (file)
@@ -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 (file)
index 0000000..600eda8
--- /dev/null
@@ -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 (file)
index 0000000..967baf3
--- /dev/null
@@ -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 () {
+}
index 7631f9e79d040e1a9c7b47dfdf10a3f3fa0c565a..955233bdc4fae5a0c0c84665b388e2c2f57e44ca 100644 (file)
@@ -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) {