~mna/snow unlisted

a70bda02e72d7ff24a35854cc0fbe2b5d12c90d7 — Martin Angers 9 months ago e5f5584
pkg/codegen: kinda works, except in a tuple conversion struct is not by ref
2 files changed, 5 insertions(+), 1 deletions(-)

M pkg/codegen/testdata/fn_interface_with_ref_method.snow
M pkg/codegen/translate.go
M pkg/codegen/testdata/fn_interface_with_ref_method.snow => pkg/codegen/testdata/fn_interface_with_ref_method.snow +2 -0
@@ 18,9 18,11 @@ fn main() {
  # this should work, s is mutable
  let tup: (int, I) = (1, s)
  tup.1.foo()
  println(s.i)
}

@extern(import: "fmt", symbol: "Println")
fn println(v: int)

#=1
#=2

M pkg/codegen/translate.go => pkg/codegen/translate.go +3 -1
@@ 628,7 628,6 @@ func (t *translator) goTypeExprFor(T semantic.Type) goast.Expr {
		}
		for i, field := range T.Fields {
			st.Fields.List[i] = &goast.Field{
				// TODO: for now, always unexported?
				Names: []*goast.Ident{{Name: t.resolver.NameForTuple(i, false)}},
				Type:  t.goTypeExprFor(field),
			}


@@ 662,6 661,9 @@ func (t *translator) convertExprFromTo(expr goast.Expr, fromT, toT semantic.Type
	// to it (as the rules for assignability are the same). Only thing is if one of the methods
	// is satisfied by a ref function, the address of expr must be returned instead.
	if semantic.AsInterfaceType(toT) != nil {
		if st := semantic.AsStructType(fromT); st != nil && st.Ctx == semantic.Mutable {
			return &goast.UnaryExpr{Op: gotoken.AND, X: expr}
		}
		return expr
	}