diff --git a/vyper/semantics/analysis/local.py b/vyper/semantics/analysis/local.py index 3d1e9b8ef1..618b5c9d2c 100644 --- a/vyper/semantics/analysis/local.py +++ b/vyper/semantics/analysis/local.py @@ -37,6 +37,7 @@ TYPE_T, AddressT, BoolT, + BytesT, DArrayT, EnumT, EventT, @@ -232,7 +233,7 @@ def visit_AnnAssign(self, node): ) typ = type_from_annotation(node.annotation, DataLocation.MEMORY) - validate_expected_type(node.value, typ) + #validate_expected_type(node.value, typ) try: self.namespace[name] = VarInfo(typ, location=DataLocation.MEMORY) @@ -262,7 +263,6 @@ def visit_Assign(self, node): "Left-hand side of assignment cannot be a HashMap without a key", node ) - validate_expected_type(node.value, target.typ) target.validate_modification(node, self.func.mutability) self.expr_visitor.visit(node.value, target.typ) @@ -691,7 +691,11 @@ def visit_Compare(self, node: vy_ast.Compare, typ: VyperType) -> None: self.visit(node.right, rtyp) def visit_Constant(self, node: vy_ast.Constant, typ: VyperType) -> None: - validate_expected_type(node, typ) + if typ in (BytesT, StringT): + typ = typ.from_literal(node) + node._metadata["type"] = typ + + typ.validate_literal(node) def visit_Index(self, node: vy_ast.Index, typ: VyperType) -> None: validate_expected_type(node.value, typ) diff --git a/vyper/semantics/types/bytestrings.py b/vyper/semantics/types/bytestrings.py index 09130626aa..b422832b44 100644 --- a/vyper/semantics/types/bytestrings.py +++ b/vyper/semantics/types/bytestrings.py @@ -60,10 +60,9 @@ def maxlen(self): def validate_literal(self, node: vy_ast.Constant) -> None: super().validate_literal(node) - - if len(node.value) != self.length: + if len(node.value) > self.length: # should always be constructed with correct length - # at the point that validate_literal is calle.d + # at the point that validate_literal is called raise CompilerPanic("unreachable") @property