~mna/snow unlisted

a1f9b2407fe7021df0672fe8548e2118afbb3c58 — Martin Angers 9 months ago 0118dd2
pkg/semantic: test assignment and interface-satisfiability
A pkg/semantic/testdata/check/interface_satisfied.snow.err => pkg/semantic/testdata/check/interface_satisfied.snow.err +3 -0
@@ 0,0 1,3 @@
testdata/interface_satisfied.snow:31:11: cannot assign type int to variable of type interface Empty
testdata/interface_satisfied.snow:34:7: cannot assign type struct S2 to variable of type interface Foo
testdata/interface_satisfied.snow:35:7: cannot assign type struct S3 to variable of type interface Foo

A pkg/semantic/testdata/check/interface_satisfied.snow.want => pkg/semantic/testdata/check/interface_satisfied.snow.want +69 -0
@@ 0,0 1,69 @@
file testdata/interface_satisfied.snow [0, 1, 3, 2]
  fn main [let: () -> void]
    block [11]
      var: empty [var: interface Empty]
        ident Empty [type: interface Empty]
      var: f [var: interface Foo]
        ident Foo [type: interface Foo]
      var: integer [var: int]
        ident int [type: int]
      var: s1 [var: struct S1]
        ident S1 [type: struct S1]
      assign
        ident empty [var: interface Empty]
        ident empty [var: interface Empty]
      assign
        ident empty [var: interface Empty]
        implicit conv [value: interface Empty]
          ident f [var: interface Foo]
      assign
        ident empty [var: interface Empty]
        implicit conv [value: interface Empty]
          ident s1 [var: struct S1]
      assign
        ident empty [var: interface Empty]
        ident integer [var: int]
      assign
        ident f [var: interface Foo]
        implicit conv [value: interface Foo]
          call [0] [value: struct S1]
            ident S1 [type: struct S1]
      assign
        ident f [var: interface Foo]
        call [0] [value: struct S2]
          ident S2 [type: struct S2]
      assign
        ident f [var: interface Foo]
        call [0] [value: struct S3]
          ident S3 [type: struct S3]
  struct S1 [0, 2, 0, 0] [type: struct S1]
    fn foo [let: (int) -> int]
      let: x [let: int]
        ident int [type: int]
      ident int [type: int]
      block [0]
    fn bar [let: (string) -> void]
      let: s [let: string]
        ident string [type: string]
      block [0]
  struct S2 [0, 2, 0, 0] [type: struct S2]
    fn bar [let: (string) -> void]
      let: s [let: string]
        ident string [type: string]
      block [0]
    fn quz [let: (bool) -> void]
      let: b [let: bool]
        ident bool [type: bool]
      block [0]
  struct S3 [0, 1, 0, 0] [type: struct S3]
    fn foo [let: (uint) -> int]
      let: u [let: uint]
        ident uint [type: uint]
      ident int [type: int]
      block [0]
  interface Empty [0] [type: interface Empty]
  interface Foo [1] [type: interface Foo]
    fn foo [let: (int) -> int]
      let: i [let: int]
        ident int [type: int]
      ident int [type: int]

A pkg/semantic/testdata/interface_satisfied.snow => pkg/semantic/testdata/interface_satisfied.snow +37 -0
@@ 0,0 1,37 @@
interface Empty {
}

interface Foo {
  fn foo(i: int) -> int
}

struct S1 {
  fn foo(x: int) -> int {}
  fn bar(s: string) {}
}

struct S2 {
  fn bar(s: string) {}
  fn quz(b: bool) {}
}

struct S3 {
  fn foo(u: uint) -> int {}
}

fn main() {
  var empty: Empty
  var f: Foo
  var integer: int
  var s1: S1

  empty = empty   # self assignment should work
  empty = f       # ok, everything satisfies empty
  empty = s1      # yep
  empty = integer # well no, not quite everything!

  f = S1() # all good, S1.foo exists and same types
  f = S2() # nope
  f = S3() # types don't match
}


A pkg/semantic/testdata/scopes/interface_satisfied.snow.err => pkg/semantic/testdata/scopes/interface_satisfied.snow.err +0 -0

A pkg/semantic/testdata/scopes/interface_satisfied.snow.want => pkg/semantic/testdata/scopes/interface_satisfied.snow.want +79 -0
@@ 0,0 1,79 @@
1 *semantic.Unit {
.  bool
.  extern
.  f32
.  f64
.  false
.  float
.  i16
.  i32
.  i64
.  i8
.  int
.  string
.  true
.  u16
.  u32
.  u64
.  u8
.  uint
.  void
.  2 *semantic.Struct {
.  .  import
.  .  pkg
.  .  symbol
.  }
.  3 *semantic.File {
.  .  Empty
.  .  Foo
.  .  S1
.  .  S2
.  .  S3
.  .  main
.  .  4 *semantic.Interface {
.  .  }
.  .  5 *semantic.Interface {
.  .  .  foo
.  .  .  6 *semantic.Fn {
.  .  .  .  i
.  .  .  }
.  .  }
.  .  7 *semantic.Struct {
.  .  .  bar
.  .  .  foo
.  .  .  8 *semantic.Fn {
.  .  .  .  self
.  .  .  .  x
.  .  .  }
.  .  .  9 *semantic.Fn {
.  .  .  .  s
.  .  .  .  self
.  .  .  }
.  .  }
.  .  10 *semantic.Struct {
.  .  .  bar
.  .  .  quz
.  .  .  11 *semantic.Fn {
.  .  .  .  s
.  .  .  .  self
.  .  .  }
.  .  .  12 *semantic.Fn {
.  .  .  .  b
.  .  .  .  self
.  .  .  }
.  .  }
.  .  13 *semantic.Struct {
.  .  .  foo
.  .  .  14 *semantic.Fn {
.  .  .  .  self
.  .  .  .  u
.  .  .  }
.  .  }
.  .  15 *semantic.Fn {
.  .  .  empty
.  .  .  f
.  .  .  integer
.  .  .  s1
.  .  }
.  }
}

A pkg/semantic/testdata/static/interface_satisfied.snow.err => pkg/semantic/testdata/static/interface_satisfied.snow.err +3 -0
@@ 0,0 1,3 @@
testdata/interface_satisfied.snow:31:11: cannot assign type int to variable of type interface Empty
testdata/interface_satisfied.snow:34:7: cannot assign type struct S2 to variable of type interface Foo
testdata/interface_satisfied.snow:35:7: cannot assign type struct S3 to variable of type interface Foo

A pkg/semantic/testdata/static/interface_satisfied.snow.want => pkg/semantic/testdata/static/interface_satisfied.snow.want +7 -0
@@ 0,0 1,7 @@
testdata/interface_satisfied.snow:28:11: empty
testdata/interface_satisfied.snow:29:11: f
testdata/interface_satisfied.snow:30:11: s1
testdata/interface_satisfied.snow:31:11: integer
testdata/interface_satisfied.snow:33:7: S1
testdata/interface_satisfied.snow:34:7: S2
testdata/interface_satisfied.snow:35:7: S3

A pkg/semantic/testdata/types/interface_satisfied.snow.err => pkg/semantic/testdata/types/interface_satisfied.snow.err +0 -0

A pkg/semantic/testdata/types/interface_satisfied.snow.want => pkg/semantic/testdata/types/interface_satisfied.snow.want +66 -0
@@ 0,0 1,66 @@
file testdata/interface_satisfied.snow [0, 1, 3, 2]
  fn main [let: () -> void]
    block [11]
      var: empty [var: interface Empty]
        ident Empty [type: interface Empty]
      var: f [var: interface Foo]
        ident Foo [type: interface Foo]
      var: integer [var: int]
        ident int [type: int]
      var: s1 [var: struct S1]
        ident S1 [type: struct S1]
      assign
        ident empty [var: interface Empty]
        ident empty [var: interface Empty]
      assign
        ident empty [var: interface Empty]
        ident f [var: interface Foo]
      assign
        ident empty [var: interface Empty]
        ident s1 [var: struct S1]
      assign
        ident empty [var: interface Empty]
        ident integer [var: int]
      assign
        ident f [var: interface Foo]
        call [0] [value: struct S1]
          ident S1 [type: struct S1]
      assign
        ident f [var: interface Foo]
        call [0] [value: struct S2]
          ident S2 [type: struct S2]
      assign
        ident f [var: interface Foo]
        call [0] [value: struct S3]
          ident S3 [type: struct S3]
  struct S1 [0, 2, 0, 0] [type: struct S1]
    fn foo [let: (int) -> int]
      let: x [let: int]
        ident int [type: int]
      ident int [type: int]
      block [0]
    fn bar [let: (string) -> void]
      let: s [let: string]
        ident string [type: string]
      block [0]
  struct S2 [0, 2, 0, 0] [type: struct S2]
    fn bar [let: (string) -> void]
      let: s [let: string]
        ident string [type: string]
      block [0]
    fn quz [let: (bool) -> void]
      let: b [let: bool]
        ident bool [type: bool]
      block [0]
  struct S3 [0, 1, 0, 0] [type: struct S3]
    fn foo [let: (uint) -> int]
      let: u [let: uint]
        ident uint [type: uint]
      ident int [type: int]
      block [0]
  interface Empty [0] [type: interface Empty]
  interface Foo [1] [type: interface Foo]
    fn foo [let: (int) -> int]
      let: i [let: int]
        ident int [type: int]
      ident int [type: int]