Skip to content

Commit

Permalink
change Constant node
Browse files Browse the repository at this point in the history
  • Loading branch information
tserg committed Jul 20, 2023
1 parent 7bae576 commit 811ece1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
10 changes: 7 additions & 3 deletions vyper/semantics/analysis/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
TYPE_T,
AddressT,
BoolT,
BytesT,
DArrayT,
EnumT,
EventT,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 2 additions & 3 deletions vyper/semantics/types/bytestrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 811ece1

Please sign in to comment.