hashicorp / hcl2

Former temporary home for experimental new version of HCL
https://github.com/hashicorp/hcl
Mozilla Public License 2.0
373 stars 66 forks source link

Forbid zero-prefixed number literals to avoid octal confusion #86

Closed apparentlymart closed 4 years ago

apparentlymart commented 5 years ago

Those coming from C-based languages may bring an expectation that zero-prefixed number literals are to be interpreted as octal. HCL 2 does not do that, and currently seems to just interpret them as decimal numbers after stripping the leading zero, which can lead to confusing, hard-to-explain results.

As a compromise then, we should detect when a numeric literal has leading zeros and produce an error about it which includes a specific note about octal numbers. Something like:

Leading zeroes are not allowed on number literals. If you were trying to write a number in octal, please note that only decimal number literals are allowed.

apparentlymart commented 4 years ago

Unfortunately we didn't have time to implement this before shipping Terraform with HCL 2 and so the current behavior is now a compatibility constraint. We may reconsider this for a hypothetical future major version of HCL 2, but will not be able to make the change I described above in the near future.