From f6fe9b5c697c9799e0170891cc32e48185aa12a1 Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Sat, 28 Jul 2018 15:44:15 -0700 Subject: [PATCH] hcl: Deduplicate symbols when printing diagnostic messages --- hcl/diagnostic_text.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/hcl/diagnostic_text.go b/hcl/diagnostic_text.go index 9e47e9f..0b4a262 100644 --- a/hcl/diagnostic_text.go +++ b/hcl/diagnostic_text.go @@ -147,6 +147,7 @@ func (w *diagnosticTextWriter) WriteDiagnostic(diag *Diagnostic) error { vars := expr.Variables() stmts := make([]string, 0, len(vars)) + seen := make(map[string]struct{}, len(vars)) for _, traversal := range vars { val, diags := traversal.TraverseAbs(ctx) if diags.HasErrors() { @@ -157,6 +158,9 @@ func (w *diagnosticTextWriter) WriteDiagnostic(diag *Diagnostic) error { } traversalStr := w.traversalStr(traversal) + if _, exists := seen[traversalStr]; exists { + continue // don't show duplicates when the same variable is referenced multiple times + } switch { case !val.IsKnown(): // Can't say anything about this yet, then. @@ -166,6 +170,7 @@ func (w *diagnosticTextWriter) WriteDiagnostic(diag *Diagnostic) error { default: stmts = append(stmts, fmt.Sprintf("%s as %s", traversalStr, w.valueStr(val))) } + seen[traversalStr] = struct{}{} } sort.Strings(stmts) // FIXME: Should maybe use a traversal-aware sort that can sort numeric indexes properly?