[vala] Report an error when parsing non-public struct fields
- From: Luca Bruno <lucabru src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala] Report an error when parsing non-public struct fields
- Date: Mon, 11 Aug 2014 12:40:00 +0000 (UTC)
commit 29b93a27ddffb0cd77cdf44281a8889c22aff994
Author: Luca Bruno <lucabru src gnome org>
Date: Mon Aug 11 14:32:23 2014 +0200
Report an error when parsing non-public struct fields
Fixes bug 683413
tests/structs/structs.vala | 12 ------------
vala/valaparser.vala | 7 ++++++-
vala/valastruct.vala | 1 -
3 files changed, 6 insertions(+), 14 deletions(-)
---
diff --git a/tests/structs/structs.vala b/tests/structs/structs.vala
index 543975a..e991121 100644
--- a/tests/structs/structs.vala
+++ b/tests/structs/structs.vala
@@ -9,15 +9,6 @@ public struct PublicStruct {
public int field;
}
-struct StructWithPrivateField {
- private int field;
-
- public void test () {
- field = 1;
- stdout.printf ("StructWithPrivateField: field = %d\n", field);
- }
-}
-
struct StructWithCreationMethod {
public StructWithCreationMethod () {
stdout.printf ("StructWithCreationMethod\n");
@@ -78,9 +69,6 @@ void main () {
test_out_parameter (out simple_struct);
stdout.printf ("after test_out_parameter: st.field = %d\n", simple_struct.field);
- var struct_with_private_field = StructWithPrivateField ();
- struct_with_private_field.test ();
-
stdout.printf (".\n");
}
diff --git a/vala/valaparser.vala b/vala/valaparser.vala
index c465a8e..89218eb 100644
--- a/vala/valaparser.vala
+++ b/vala/valaparser.vala
@@ -2565,7 +2565,7 @@ public class Vala.Parser : CodeVisitor {
void parse_field_declaration (Symbol parent, List<Attribute>? attrs) throws ParseError {
var begin = get_location ();
- var access = parse_access_modifier ();
+ var access = parse_access_modifier ((parent is Struct) ? SymbolAccessibility.PUBLIC :
SymbolAccessibility.PRIVATE);
var flags = parse_member_declaration_modifiers ();
var type = parse_type (true, true);
string id = parse_identifier ();
@@ -2573,6 +2573,11 @@ public class Vala.Parser : CodeVisitor {
var f = new Field (id, type, null, get_src (begin), comment);
f.access = access;
+
+ if (parent is Struct && f.access != SymbolAccessibility.PUBLIC) {
+ Report.error (f.source_reference, "accessibility of struct fields can only be
`public`");
+ }
+
set_attributes (f, attrs);
if (ModifierFlags.STATIC in flags) {
f.binding = MemberBinding.STATIC;
diff --git a/vala/valastruct.vala b/vala/valastruct.vala
index b9229e0..dbbf629 100644
--- a/vala/valastruct.vala
+++ b/vala/valastruct.vala
@@ -170,7 +170,6 @@ public class Vala.Struct : TypeSymbol {
* @param f a field
*/
public override void add_field (Field f) {
- // TODO report error when `private' or `protected' has been specified
f.access = SymbolAccessibility.PUBLIC;
fields.add (f);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]