diff --git a/lang/interpret_test/TestAstFunc2/struct-duplicate4.output b/lang/interpret_test/TestAstFunc2/struct-duplicate4.output new file mode 100644 index 00000000..5d8fb049 --- /dev/null +++ b/lang/interpret_test/TestAstFunc2/struct-duplicate4.output @@ -0,0 +1 @@ +# err: err1: parser: `syntax error: unexpected $end, expecting EQUALS` @1:6 diff --git a/lang/interpret_test/TestAstFunc2/struct-duplicate4/main.mcl b/lang/interpret_test/TestAstFunc2/struct-duplicate4/main.mcl new file mode 100644 index 00000000..7cc41f75 --- /dev/null +++ b/lang/interpret_test/TestAstFunc2/struct-duplicate4/main.mcl @@ -0,0 +1 @@ +$d []struct{x int;x float} diff --git a/lang/parser.y b/lang/parser.y index 569a1d1f..6ea9c5cf 100644 --- a/lang/parser.y +++ b/lang/parser.y @@ -1180,14 +1180,14 @@ type: strs := []string{} for _, arg := range $3.args { s := fmt.Sprintf("%s %s", arg.Name, arg.Type.String()) - if _, exists := names[s]; exists { + if _, exists := names[arg.Name]; exists { // duplicate field name used err := fmt.Errorf("duplicate struct field of `%s`", s) // this will ultimately cause a parser error to occur... yylex.Error(fmt.Sprintf("%s: %+v", ErrParseSetType, err)) break // we must skip, because code continues! } - names[s] = struct{}{} + names[arg.Name] = struct{}{} strs = append(strs, s) }