~mna/snow

snow/pkg/semantic/testdata/fn_generic_interface.snow -rw-r--r-- 436 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
interface I[$T] {
  fn foo(t: $T) -> $T
}

struct S {
  fn foo(i: int) -> int {}
}

struct G[$T] {
  fn foo(t: $T) -> $T {}
}

fn main() {
  var ifaceInt: I[int] = S()
  var res = ifaceInt.foo(1)
  var gInt: G[int]
  var gres = gInt.foo(1)

  ifaceInt = G[int]()
  res = ifaceInt.foo(2)

  # this should fail
  ifaceInt = G[bool]()

  # this should work
  var ifaceString: I[string]
  ifaceString = G[string]()
  ifaceString.foo("a")
}