objects/property-notify-owned-getter.vala \
objects/property-ownership.vala \
objects/property-read-only-auto.vala \
+ objects/property-read-only-member-write.test \
objects/property-read-only-write.test \
+ objects/property-construct-only.vala \
objects/property-construct-only-write.test \
+ objects/property-construct-only-write-after.test \
objects/property-construct-only-write-foreign.test \
objects/property-delegate.vala \
objects/property-delegate-owned.vala \
objects/property-simple-type-struct-nullable.vala \
objects/property-static.vala \
objects/property-struct-no-gtype.vala \
+ objects/property-write-only-member-read.test \
objects/regex.vala \
objects/sealed-abstract-class.test \
objects/sealed-class.test \
--- /dev/null
+Invalid Code
+
+class Foo : GLib.Object {
+ public string manam { get; construct; }
+}
+
+void main () {
+ var foo = new Foo ();
+ foo.manam = "manam";
+}
--- /dev/null
+class Foo : GLib.Object {
+ public string manam { get; construct; }
+
+ construct {
+ manam = "foo";
+ }
+}
+
+class Bar : Foo {
+ construct {
+ manam = "bar";
+ }
+}
+
+class Faz : GLib.Object {
+ public string manam { get; construct; }
+
+ public Faz () {
+ Object (manam : "faz");
+ }
+}
+
+class Baz : Faz {
+ public Baz () {
+ Object (manam : "baz");
+ }
+}
+
+void main () {
+ {
+ var foo = new Foo ();
+ assert (foo.manam == "foo");
+ }
+ {
+ var bar = new Bar ();
+ assert (bar.manam == "bar");
+ }
+ {
+ var faz = new Faz ();
+ assert (faz.manam == "faz");
+ }
+ {
+ var baz = new Baz ();
+ assert (baz.manam == "baz");
+ }
+}
--- /dev/null
+Invalid Code
+
+class Foo : GLib.Object {
+ public string manam { get; construct; }
+}
+
+class Bar : GLib.Object {
+ construct {
+ var foo = new Foo ();
+ foo.manam = "manam";
+ }
+}
+
+void main () {
+}
--- /dev/null
+Invalid Code
+
+class Foo : GLib.Object {
+ public string manam { set; }
+}
+
+void main () {
+ var foo = new Foo ();
+ var s = foo.manam;
+}
dynamic_prop.property_type = right.value_type.copy ();
left.value_type = dynamic_prop.property_type.copy ();
}
-
- if (prop.set_accessor == null
- || (!prop.set_accessor.writable && !(context.analyzer.find_current_method () is CreationMethod || context.analyzer.is_in_constructor ()))) {
- ma.error = true;
- Report.error (ma.source_reference, "Property `%s' is read-only".printf (prop.get_full_name ()));
- return false;
- } else if (!context.deprecated
- && !prop.set_accessor.writable
- && context.analyzer.find_current_method () is CreationMethod) {
- if (ma.inner.symbol_reference != context.analyzer.find_current_method ().this_parameter) {
- // trying to set construct-only property in creation method for foreign instance
- error = true;
- Report.error (ma.source_reference, "Property `%s' is read-only".printf (prop.get_full_name ()));
- return false;
- } else {
- error = true;
- Report.error (ma.source_reference, "Cannot assign to construct-only properties, use Object (property: value) constructor chain up");
- return false;
- }
- }
} else if (ma.symbol_reference is ArrayLengthField && ((ArrayType) ma.inner.value_type).inline_allocated) {
error = true;
Report.error (source_reference, "`length' field of fixed length arrays is read-only");
error = true;
Report.error (source_reference, "Property `%s' is read-only".printf (prop.get_full_name ()));
return false;
+ } else if (!prop.set_accessor.writable && prop.set_accessor.construction) {
+ if (context.analyzer.find_current_method () is CreationMethod) {
+ error = true;
+ Report.error (source_reference, "Cannot assign to construct-only properties, use Object (property: value) constructor chain up");
+ return false;
+ } else if (context.analyzer.is_in_constructor ()) {
+ if (!context.analyzer.current_type_symbol.is_subtype_of ((TypeSymbol) prop.parent_symbol)) {
+ error = true;
+ Report.error (source_reference, "Cannot assign to construct-only property `%s' in `construct' of `%s'".printf (prop.get_full_name (), context.analyzer.current_type_symbol.get_full_name ()));
+ return false;
+ }
+ } else {
+ error = true;
+ Report.error (source_reference, "Cannot assign to construct-only property in this context");
+ return false;
+ }
}
if (prop.access == SymbolAccessibility.PUBLIC) {
access = prop.set_accessor.access;