Add support for class member variable

supersedes #1417
trees are supposed to be immutable but since this never escapes this function it is fine. Maybe add a comment?