we can't compare location if either are nil

This commit is contained in:
James Bardin 2025-04-02 10:58:19 -04:00
parent c6c21a89a1
commit 291d26ce19
2 changed files with 31 additions and 3 deletions

View file

@ -733,6 +733,35 @@ func TestAppendWithoutDuplicates(t *testing.T) {
},
},
},
"hcl.Diagnostic no-location": {
// Extra can contain anything, and we don't know how to compare
// those values, so we can't dedupe them
func(diags Diagnostics) Diagnostics {
diags = diags.Append(&hcl.Diagnostic{
Severity: hcl.DiagError,
Summary: "Something bad happened",
Detail: "It was really, really bad.",
})
diags = diags.Append(&hcl.Diagnostic{
Severity: hcl.DiagError,
Summary: "Something bad happened",
Detail: "It was really, really bad.",
})
return diags
},
[]diagFlat{
{
Severity: Error,
Summary: "Something bad happened",
Detail: "It was really, really bad.",
},
{
Severity: Error,
Summary: "Something bad happened",
Detail: "It was really, really bad.",
},
},
},
}
for name, test := range tests {
@ -756,9 +785,7 @@ func TestAppendWithoutDuplicates(t *testing.T) {
}
if !reflect.DeepEqual(got, test.Want) {
// t.Errorf("wrong result\ngot: %swant: %s", spew.Sdump(got), spew.Sdump(test.Want))
t.Errorf("wrong result\ngot: %#v\nwant: %#v", got, test.Want)
}
})
}

View file

@ -85,8 +85,9 @@ func (d hclDiagnostic) Equals(otherDiag ComparableDiagnostic) bool {
func hclRangeEquals(l, r *hcl.Range) bool {
if l == nil || r == nil {
return l == r
return false
}
if l.Filename != r.Filename {
return false
}