~mna/snow unlisted

0118dd2238fd52af539409d81db0e429e6cc2976 — Martin Angers 9 months ago 0008f4d
pkg/semantic: test assign to interface and call via interface
A pkg/semantic/testdata/check/fn_assign_call_interface.snow.err => pkg/semantic/testdata/check/fn_assign_call_interface.snow.err +0 -0

A pkg/semantic/testdata/check/fn_assign_call_interface.snow.want => pkg/semantic/testdata/check/fn_assign_call_interface.snow.want +32 -0
@@ 0,0 1,32 @@
file testdata/fn_assign_call_interface.snow [0, 2, 1, 1]
  fn println [let: (string) -> void]
    @ [import, symbol] [2] [value: struct extern]
      ident extern [type: struct extern]
      string ["fmt"] [const: string]
      string ["Println"] [const: string]
    let: s [let: string]
      ident string [type: string]
  fn main [let: () -> void]
    block [2]
      let:= iface [let: interface I]
        ident I [type: interface I]
        implicit conv [value: interface I]
          call [s] [1] [value: struct S]
            ident S [type: struct S]
            string ["hello!"] [const: string]
      expr
        call [0] [value: void]
          select [let: () -> void]
            ident iface [let: interface I]
            ident foo [let: () -> void]
  struct S [1, 1, 0, 0] [type: struct S]
    let: s [let: string]
      ident string [type: string]
    fn foo [let: () -> void]
      block [1]
        expr
          call [1] [value: void]
            ident println [let: (string) -> void]
            ident s [let: string]
  interface I [1] [type: interface I]
    fn foo [let: () -> void]

A pkg/semantic/testdata/fn_assign_call_interface.snow => pkg/semantic/testdata/fn_assign_call_interface.snow +19 -0
@@ 0,0 1,19 @@
interface I {
  fn foo()
}

struct S {
  let s: string

  fn foo() {
    println(s)
  }
}

@extern(import: "fmt", symbol: "Println")
fn println(s: string)

fn main() {
  let iface: I = S(s: "hello!")
  iface.foo()
}

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

A pkg/semantic/testdata/scopes/fn_assign_call_interface.snow.want => pkg/semantic/testdata/scopes/fn_assign_call_interface.snow.want +50 -0
@@ 0,0 1,50 @@
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 {
.  .  I
.  .  S
.  .  main
.  .  println
.  .  4 *semantic.Interface {
.  .  .  foo
.  .  .  5 *semantic.Fn {
.  .  .  }
.  .  }
.  .  6 *semantic.Struct {
.  .  .  foo
.  .  .  s
.  .  .  7 *semantic.Fn {
.  .  .  .  self
.  .  .  }
.  .  }
.  .  8 *semantic.Fn {
.  .  .  s
.  .  }
.  .  9 *semantic.Fn {
.  .  .  iface
.  .  }
.  }
}

A pkg/semantic/testdata/static/fn_assign_call_interface.snow.err => pkg/semantic/testdata/static/fn_assign_call_interface.snow.err +0 -0

A pkg/semantic/testdata/static/fn_assign_call_interface.snow.want => pkg/semantic/testdata/static/fn_assign_call_interface.snow.want +5 -0
@@ 0,0 1,5 @@
testdata/fn_assign_call_interface.snow:9:5: println
testdata/fn_assign_call_interface.snow:9:13: s
testdata/fn_assign_call_interface.snow:17:18: S
testdata/fn_assign_call_interface.snow:18:3: iface
testdata/fn_assign_call_interface.snow:18:9: foo

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

A pkg/semantic/testdata/types/fn_assign_call_interface.snow.want => pkg/semantic/testdata/types/fn_assign_call_interface.snow.want +31 -0
@@ 0,0 1,31 @@
file testdata/fn_assign_call_interface.snow [0, 2, 1, 1]
  fn println [let: (string) -> void]
    @ [import, symbol] [2] [value: struct extern]
      ident extern [type: struct extern]
      string ["fmt"] [const: string]
      string ["Println"] [const: string]
    let: s [let: string]
      ident string [type: string]
  fn main [let: () -> void]
    block [2]
      let:= iface [let: interface I]
        ident I [type: interface I]
        call [s] [1] [value: struct S]
          ident S [type: struct S]
          string ["hello!"] [const: string]
      expr
        call [0] [value: void]
          select [let: () -> void]
            ident iface [let: interface I]
            ident foo [let: () -> void]
  struct S [1, 1, 0, 0] [type: struct S]
    let: s [let: string]
      ident string [type: string]
    fn foo [let: () -> void]
      block [1]
        expr
          call [1] [value: void]
            ident println [let: (string) -> void]
            ident s [let: string]
  interface I [1] [type: interface I]
    fn foo [let: () -> void]

M pkg/semantic/type.go => pkg/semantic/type.go +1 -0
@@ 577,6 577,7 @@ func (i *InterfaceType) ResolveGeneric(resolve map[*GenericType]Type) Type {
func (i *InterfaceType) typeof(sel *Ident, _ TypeContext) (Type, TypeContext) {
	for _, m := range i.Decl.Methods {
		if m.Ident() == sel.Name {
			sel.Ref = m
			return i.typeOfSel(m.Type()), m.TypeContext()
		}
	}

M pkg/semantic/typeassign_pass_test.go => pkg/semantic/typeassign_pass_test.go +1 -1
@@ 40,7 40,7 @@ func TestTypes(t *testing.T) {
			// sanity check invariants:
			// - all expressions have a type
			// - all declarations have a type
			// - all valid (non-tuple) identifiers have a Ref
			// - all valid (non-tuple, non interface methods) identifiers have a Ref
			var check visitorFunc
			check = func(n semantic.Node) semantic.Visitor {
				if n == nil {