Files
wren/test/language/class_var/without_initializer.wren
Bob Nystrom 8ed0cde91c Allow "var" in a class body for defining "properties".
A property is a field with an implicit getter, setter, and optional
class body initializer.

It's handy for defining publicly visible state in a class. When modules
are classes, this is needed for "top level" variables.

Right now, a class var gets both a getter and setter. It would be nice
to also have something like "val" for properties that are publicly
visible but not settable.

Also, still need to support "static var" for metaclass properties.
2015-12-21 08:04:39 -08:00

13 lines
254 B
Plaintext

class Foo {
construct new() {}
var bar
}
var foo = Foo.new()
System.print(foo.bar) // expect: null
System.print(foo.bar = "value") // expect: value
System.print(foo.bar) // expect: value
// TODO: Duplicate.
// TODO: static var.