From 55573c672902727b3c5b37801239972f1e8955b9 Mon Sep 17 00:00:00 2001 From: Yurii Soldak Date: Fri, 26 Aug 2022 21:37:56 +0200 Subject: [PATCH] targets: fail fast on duplicate values in target field slices --- compileopts/target.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/compileopts/target.go b/compileopts/target.go index 15bfaf781..aa2c432d4 100644 --- a/compileopts/target.go +++ b/compileopts/target.go @@ -88,8 +88,17 @@ func (spec *TargetSpec) overrideProperties(child *TargetSpec) { if !src.IsNil() { dst.Set(src) } - case reflect.Slice: // for slices, append the field + case reflect.Slice: // for slices, append the field and check for duplicates dst.Set(reflect.AppendSlice(dst, src)) + for i := 0; i < dst.Len(); i++ { + v := dst.Index(i).String() + for j := i + 1; j < dst.Len(); j++ { + w := dst.Index(j).String() + if v == w { + panic("duplicate value '" + v + "' in field : " + field.Name) + } + } + } default: panic("unknown field type : " + kind.String()) }