]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Deny access to protected constructors
authorRico Tzschichholz <ricotz@ubuntu.com>
Sat, 8 Oct 2016 20:13:01 +0000 (22:13 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Sat, 8 Oct 2016 20:14:14 +0000 (22:14 +0200)
Based on patch by Timm Bäder <mail@baedert.org>

https://bugzilla.gnome.org/show_bug.cgi?id=760031

tests/Makefile.am
tests/objects/bug760031.test [new file with mode: 0644]
vala/valaobjectcreationexpression.vala

index e10be4d5d43cb984c6c7861736ae81c092382e6a..a9d0c18e4a7454bda21ffefc36a76af158b17fd1 100644 (file)
@@ -178,6 +178,7 @@ TESTS = \
        objects/bug702736.vala \
        objects/bug702846.vala \
        objects/bug751338.vala \
+       objects/bug760031.test \
        objects/bug767092.test \
        objects/bug768823.test \
        objects/bug615830-1.test \
diff --git a/tests/objects/bug760031.test b/tests/objects/bug760031.test
new file mode 100644 (file)
index 0000000..5843982
--- /dev/null
@@ -0,0 +1,10 @@
+Invalid Code
+
+class Foo {
+       protected Foo () {
+       }
+}
+
+void main () {
+       new Foo ();
+}
index 8481f443e5edb48246c92db87c91d14a18d45422..06995030b063ff9aee89e2e5dec22e9e5c622b0d 100644 (file)
@@ -173,7 +173,10 @@ public class Vala.ObjectCreationExpression : Expression {
                checked = true;
 
                if (member_name != null) {
-                       member_name.check (context);
+                       if (!member_name.check (context)) {
+                               error = true;
+                               return false;
+                       }
                }
 
                TypeSymbol type = null;
@@ -280,7 +283,8 @@ public class Vala.ObjectCreationExpression : Expression {
                                symbol_reference.version.check (source_reference);
                        }
 
-                       if (symbol_reference != null && symbol_reference.access == SymbolAccessibility.PRIVATE) {
+                       if (symbol_reference != null
+                           && (symbol_reference.access == SymbolAccessibility.PRIVATE || symbol_reference.access == SymbolAccessibility.PROTECTED)) {
                                bool in_target_type = false;
                                for (Symbol this_symbol = context.analyzer.current_symbol; this_symbol != null; this_symbol = this_symbol.parent_symbol) {
                                        if (this_symbol == cl) {
@@ -291,7 +295,7 @@ public class Vala.ObjectCreationExpression : Expression {
 
                                if (!in_target_type) {
                                        error = true;
-                                       Report.error (source_reference, "Access to private member `%s' denied".printf (symbol_reference.get_full_name ()));
+                                       Report.error (source_reference, "Access to non-public constructor `%s' denied".printf (symbol_reference.get_full_name ()));
                                        return false;
                                }
                        }