diff --git a/tests/unit/ast/nodes/test_hex.py b/tests/unit/ast/nodes/test_hex.py index 1b61764d574..7168defa99d 100644 --- a/tests/unit/ast/nodes/test_hex.py +++ b/tests/unit/ast/nodes/test_hex.py @@ -33,6 +33,9 @@ def foo(): """ foo: constant(bytes4) = 0x12_34_56 """, + """ +foo: constant(bytes4) = 0X12345678 + """, ] diff --git a/vyper/ast/nodes.py b/vyper/ast/nodes.py index f4c99b7952d..991edeca6ee 100644 --- a/vyper/ast/nodes.py +++ b/vyper/ast/nodes.py @@ -854,10 +854,15 @@ class Hex(Constant): def validate(self): if "_" in self.value: + # TODO: revisit this, we should probably allow underscores raise InvalidLiteral("Underscores not allowed in hex literals", self) if len(self.value) % 2: raise InvalidLiteral("Hex notation requires an even number of digits", self) + if self.value.startswith("0X"): + hint = f"Did you mean `0x{self.value[2:]}`?" + raise InvalidLiteral("Hex literal begins with 0X!", self, hint=hint) + @property def n_nibbles(self): """