Repository: traefik/yaegi (Go)

Issue:
undefined selector error for type alias of named array type
```go
func TestIssue1150(t *testing.T) {
	i := interp.New(interp.Options{})
	_, err := i.Eval(`
		type Vec3 [3]float32
		func (v Vec3) LenSqr() float32 { return v[0]*v[0] + v[1]*v[1] + v[2]*v[2] }
		type Vec = Vec3
	`)
	if err != nil {
		t.Fatal(err)
	}

	runTests(t, i, []testCase{
		{src: "Vec{1, 2, 3}.LenSqr()", res: "14"},
	})
}

```

Expected result: test succeeds.

Got:
```console
$ go test -run=TestIssue1150 ./interp/
--- FAIL: TestIssue1150 (0.00s)
    --- FAIL: TestIssue1150/#00 (0.00s)
        interp_eval_test.go:784: got an error: 1:28: undefined selector: LenSqr
FAIL
FAIL    github.com/traefik/yaegi/interp 0.004s
FAIL
```



Discussion:

Patch:
diff --git a/interp/run.go b/interp/run.go
index c9064e796..5cf271b7e 100644
--- a/interp/run.go
+++ b/interp/run.go
@@ -2308,12 +2308,13 @@ func arrayLit(n *node) {
 	index := make([]int, len(child))
 	var max, prev int
 
+	ntyp := n.typ.resolveAlias()
 	for i, c := range child {
 		if c.kind == keyValueExpr {
-			values[i] = genDestValue(n.typ.val, c.child[1])
+			values[i] = genDestValue(ntyp.val, c.child[1])
 			index[i] = int(vInt(c.child[0].rval))
 		} else {
-			values[i] = genDestValue(n.typ.val, c)
+			values[i] = genDestValue(ntyp.val, c)
 			index[i] = prev
 		}
 		prev = index[i] + 1
diff --git a/interp/type.go b/interp/type.go
index 238062a6f..9112bd73c 100644
--- a/interp/type.go
+++ b/interp/type.go
@@ -1311,6 +1311,13 @@ func (t *itype) methodCallType() reflect.Type {
 	return reflect.FuncOf(it, ot, t.rtype.IsVariadic())
 }
 
+func (t *itype) resolveAlias() *itype {
+	for t.cat == aliasT {
+		t = t.val
+	}
+	return t
+}
+
 // GetMethod returns a pointer to the method definition.
 func (t *itype) getMethod(name string) *node {
 	for _, m := range t.method {
@@ -1338,6 +1345,9 @@ func (t *itype) lookupMethod(name string) (*node, []int) {
 				}
 			}
 		}
+		if t.cat == aliasT {
+			return t.val.lookupMethod(name)
+		}
 	}
 	return m, index
 }


Test patch:
diff --git a/interp/interp_eval_test.go b/interp/interp_eval_test.go
index 340b9bac7..322f20672 100644
--- a/interp/interp_eval_test.go
+++ b/interp/interp_eval_test.go
@@ -1538,3 +1538,36 @@ func TestIssue1149(t *testing.T) {
 		{src: "Type{1, 2, 3}.Bar()", res: "foo"},
 	})
 }
+
+func TestIssue1150(t *testing.T) {
+	i := interp.New(interp.Options{})
+	_, err := i.Eval(`
+		type ArrayT [3]float32
+		type SliceT []float32
+		type StructT struct { A, B, C float32 }
+		type StructT2 struct { A, B, C float32 }
+		type FooerT interface { Foo() string }
+
+		func (v ArrayT) Foo() string { return "foo" }
+		func (v SliceT) Foo() string { return "foo" }
+		func (v StructT) Foo() string { return "foo" }
+		func (v *StructT2) Foo() string { return "foo" }
+
+		type Array = ArrayT
+		type Slice = SliceT
+		type Struct = StructT
+		type Struct2 = StructT2
+		type Fooer = FooerT
+	`)
+	if err != nil {
+		t.Fatal(err)
+	}
+
+	runTests(t, i, []testCase{
+		{desc: "array", src: "Array{1, 2, 3}.Foo()", res: "foo"},
+		{desc: "slice", src: "Slice{1, 2, 3}.Foo()", res: "foo"},
+		{desc: "struct", src: "Struct{1, 2, 3}.Foo()", res: "foo"},
+		{desc: "*struct", src: "Struct2{1, 2, 3}.Foo()", res: "foo"},
+		{desc: "interface", src: "v := Fooer(Array{1, 2, 3}); v.Foo()", res: "foo"},
+	})
+}