]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Discover invalid member access to instance field
authorRico Tzschichholz <ricotz@ubuntu.com>
Mon, 27 Nov 2017 14:25:02 +0000 (15:25 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Wed, 29 Nov 2017 16:05:40 +0000 (17:05 +0100)
https://bugzilla.gnome.org/show_bug.cgi?id=790903

codegen/valaccodememberaccessmodule.vala
tests/Makefile.am
tests/control-flow/bug790903.test [new file with mode: 0644]

index 6bb5cb22a6b205f3ddf33cc096d90b1f3ba2a65c..3efcc34455e446977bcff39193e6c49a1a265f7d 100644 (file)
@@ -571,6 +571,14 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
                                }
                                inst = pub_inst;
                        }
+
+                       if (inst == null) {
+                               // FIXME Report this with proper source-reference on the vala side!
+                               Report.error (field.source_reference, "Invalid access to instance member `%s'".printf (field.get_full_name ()));
+                               result.cvalue = new CCodeInvalidExpression ();
+                               return result;
+                       }
+
                        if (instance_target_type.data_type.is_reference_type () || (instance != null && instance.value_type is PointerType)) {
                                result.cvalue = new CCodeMemberAccess.pointer (inst, get_ccode_name (field));
                        } else {
index c82aca1399f8de2b3dfe186f67442f5896b25286..554a519ab735eb2a7e84bdaa730e76f294787687 100644 (file)
@@ -116,6 +116,7 @@ TESTS = \
        control-flow/bug691514.vala     \
        control-flow/bug736774-1.vala \
        control-flow/bug736774-2.vala \
+       control-flow/bug790903.test \
        enums/enum_only.vala \
        enums/enums.vala \
        enums/flags.vala \
diff --git a/tests/control-flow/bug790903.test b/tests/control-flow/bug790903.test
new file mode 100644 (file)
index 0000000..5d088aa
--- /dev/null
@@ -0,0 +1,9 @@
+Invalid Code
+
+class Foo {
+       public string field;
+}
+
+void main () {
+       var foo = (string) Foo.field;
+}