Skip to content

Commit 01de229

Browse files
committed
nil typ checks prevent crashing -- need better tests.
apply upstream PR traefik#1695
1 parent e32a03f commit 01de229

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

cmd/yaegi/extract.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func genLicense(fname string) (string, error) {
121121
}
122122
license.WriteString("//" + txt + "\n")
123123
}
124-
if sc.Err() != nil {
124+
if err := sc.Err(); err != nil {
125125
return "", fmt.Errorf("could not scan LICENSE file: %w", err)
126126
}
127127

interp/type.go

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -733,10 +733,12 @@ func nodeType2(interp *Interpreter, sc *scope, n *node, seen []*node) (t *itype,
733733
if err != nil {
734734
return nil, err
735735
}
736-
for _, c := range arg.child[:cl] {
737-
sc.sym[c.ident] = &symbol{index: -1, kind: varTypeSym, typ: typ}
736+
if typ != nil {
737+
for _, c := range arg.child[:cl] {
738+
sc.sym[c.ident] = &symbol{index: -1, kind: varTypeSym, typ: typ}
739+
}
740+
incomplete = incomplete || typ.incomplete
738741
}
739-
incomplete = incomplete || typ.incomplete
740742
}
741743

742744
// Handle input parameters.
@@ -747,12 +749,14 @@ func nodeType2(interp *Interpreter, sc *scope, n *node, seen []*node) (t *itype,
747749
if err != nil {
748750
return nil, err
749751
}
750-
args = append(args, typ)
751-
// Several arguments may be factorized on the same field type.
752-
for i := 1; i < cl; i++ {
752+
if typ != nil {
753753
args = append(args, typ)
754+
// Several arguments may be factorized on the same field type.
755+
for i := 1; i < cl; i++ {
756+
args = append(args, typ)
757+
}
758+
incomplete = incomplete || typ.incomplete
754759
}
755-
incomplete = incomplete || typ.incomplete
756760
}
757761

758762
// Handle returned values.
@@ -764,12 +768,14 @@ func nodeType2(interp *Interpreter, sc *scope, n *node, seen []*node) (t *itype,
764768
if err != nil {
765769
return nil, err
766770
}
767-
rets = append(rets, typ)
768-
// Several arguments may be factorized on the same field type.
769-
for i := 1; i < cl; i++ {
771+
if typ != nil {
770772
rets = append(rets, typ)
773+
// Several arguments may be factorized on the same field type.
774+
for i := 1; i < cl; i++ {
775+
rets = append(rets, typ)
776+
}
777+
incomplete = incomplete || typ.incomplete
771778
}
772-
incomplete = incomplete || typ.incomplete
773779
}
774780
}
775781
t = funcOf(args, rets, withNode(n), withScope(sc))

0 commit comments

Comments
 (0)