diff --git a/common/ast/ast_test.go b/common/ast/ast_test.go index 886ca5d7..a4a4a57c 100644 --- a/common/ast/ast_test.go +++ b/common/ast/ast_test.go @@ -72,7 +72,11 @@ func TestASTCopy(t *testing.T) { if err != nil { t.Errorf("ast.ToAST() failed: %v", err) } - if !reflect.DeepEqual(checked, checkedRoundtrip) { + same := reflect.DeepEqual(checked.Expr(), checkedRoundtrip.Expr()) && + reflect.DeepEqual(checked.ReferenceMap(), checkedRoundtrip.ReferenceMap()) && + reflect.DeepEqual(checked.TypeMap(), checkedRoundtrip.TypeMap()) && + reflect.DeepEqual(checked.SourceInfo().MacroCalls(), checkedRoundtrip.SourceInfo().MacroCalls()) + if !same { t.Errorf("Roundtrip got %v, wanted %v", checkedRoundtrip, checked) } } diff --git a/parser/helper.go b/parser/helper.go index 182ff034..dc0c540a 100644 --- a/parser/helper.go +++ b/parser/helper.go @@ -140,15 +140,12 @@ func (p *parserHelper) id(ctx any) int64 { var offset ast.OffsetRange switch c := ctx.(type) { case antlr.ParserRuleContext: - start, stop := c.GetStart(), c.GetStop() - if stop == nil { - stop = start - } + start := c.GetStart() offset.Start = p.sourceInfo.ComputeOffset(int32(start.GetLine()), int32(start.GetColumn())) - offset.Stop = p.sourceInfo.ComputeOffset(int32(stop.GetLine()), int32(stop.GetColumn())) + offset.Stop = offset.Start + int32(len(c.GetText())) case antlr.Token: offset.Start = p.sourceInfo.ComputeOffset(int32(c.GetLine()), int32(c.GetColumn())) - offset.Stop = offset.Start + offset.Stop = offset.Start + int32(len(c.GetText())) case common.Location: offset.Start = p.sourceInfo.ComputeOffset(int32(c.Line()), int32(c.Column())) offset.Stop = offset.Start