~mna/snow

snow/pkg/semantic/testdata/struct_var_expr_call_method.snow -rw-r--r-- 514 bytes
424066c5Martin Angers doc: v0.0.5 1 year, 8 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
struct S {
  # this must not be allowed (same as x = self.f() with self undefined)
  var x: int = f()

  let y = 4
  # however it means that this would not be allowed either (y = self.z); seems ok to disallow
  var z = y

  fn f() -> int {
    # this is not allowed either, assign a field in non-ref func
    x = x + 1
    return x
  }

  ref fn f2() -> int {
    # this is allowed 
    x = x + 1

    # and so is this 
    fn inside_f2() {
      x = x + 2
    }
    inside_f2()

    return x
  }
}

fn main() {
}