[vala/0.36] codegen: Discover invalid member access to instance field



commit 85f66c820b429f58607af270990bca811bd7ff47
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Mon Nov 27 15:25:02 2017 +0100

    codegen: Discover invalid member access to instance field
    
    https://bugzilla.gnome.org/show_bug.cgi?id=790903

 codegen/valaccodememberaccessmodule.vala |    8 ++++++++
 tests/Makefile.am                        |    1 +
 tests/control-flow/bug790903.test        |    9 +++++++++
 3 files changed, 18 insertions(+), 0 deletions(-)
---
diff --git a/codegen/valaccodememberaccessmodule.vala b/codegen/valaccodememberaccessmodule.vala
index 6bb5cb2..3efcc34 100644
--- a/codegen/valaccodememberaccessmodule.vala
+++ b/codegen/valaccodememberaccessmodule.vala
@@ -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 {
diff --git a/tests/Makefile.am b/tests/Makefile.am
index eef8d31..9240423 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -115,6 +115,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
index 0000000..5d088aa
--- /dev/null
+++ b/tests/control-flow/bug790903.test
@@ -0,0 +1,9 @@
+Invalid Code
+
+class Foo {
+       public string field;
+}
+
+void main () {
+       var foo = (string) Foo.field;
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]