From: Rico Tzschichholz Date: Sat, 8 Oct 2016 20:13:01 +0000 (+0200) Subject: Deny access to protected constructors X-Git-Tag: 0.35.1~106 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=588c00e7e882de9bab1ecd256c1b90068fd8b554;p=thirdparty%2Fvala.git Deny access to protected constructors Based on patch by Timm Bäder https://bugzilla.gnome.org/show_bug.cgi?id=760031 --- diff --git a/tests/Makefile.am b/tests/Makefile.am index e10be4d5d..a9d0c18e4 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -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 index 000000000..58439823f --- /dev/null +++ b/tests/objects/bug760031.test @@ -0,0 +1,10 @@ +Invalid Code + +class Foo { + protected Foo () { + } +} + +void main () { + new Foo (); +} diff --git a/vala/valaobjectcreationexpression.vala b/vala/valaobjectcreationexpression.vala index 8481f443e..06995030b 100644 --- a/vala/valaobjectcreationexpression.vala +++ b/vala/valaobjectcreationexpression.vala @@ -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; } }