From 3e4b7e0eb20ecc20e70dbd458f7a54daf0032830 Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Mon, 1 Oct 2018 14:06:26 -0700 Subject: [PATCH] hclsyntax: If nested block doesn't parse, produce empty body Our usual rule for parse errors is to return a valid-but-incomplete object along with error diagnostics. This was violating that rule by returning a nil child body, which callers do not expect to deal with. Instead, we'll return an *empty* body, so that callers who use the partial result for careful analyses can still process the block header, without needing to guard against the body being nil. --- hcl/hclsyntax/parser.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/hcl/hclsyntax/parser.go b/hcl/hclsyntax/parser.go index 009b930..5784f0c 100644 --- a/hcl/hclsyntax/parser.go +++ b/hcl/hclsyntax/parser.go @@ -273,7 +273,10 @@ Token: return &Block{ Type: blockType, Labels: labels, - Body: nil, + Body: &Body{ + SrcRange: ident.Range, + EndRange: ident.Range, + }, TypeRange: ident.Range, LabelRanges: labelRanges,