From 9de09412c2fa8bd56cf5350c3d613cb67af2534f Mon Sep 17 00:00:00 2001 From: tserg <8017125+tserg@users.noreply.github.com> Date: Thu, 20 Jul 2023 16:42:03 +0800 Subject: [PATCH 1/6] remove else branch --- vyper/codegen/expr.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/vyper/codegen/expr.py b/vyper/codegen/expr.py index d637a454bc..1f03d8cecf 100644 --- a/vyper/codegen/expr.py +++ b/vyper/codegen/expr.py @@ -321,17 +321,17 @@ def parse_Attribute(self): "chain.id is unavailable prior to istanbul ruleset", self.expr ) return IRnode.from_list(["chainid"], typ=UINT256_T) + # Other variables - else: - sub = Expr(self.expr.value, self.context).ir_node - # contract type - if isinstance(sub.typ, InterfaceT): - # MyInterface.address - assert self.expr.attr == "address" - sub.typ = typ - return sub - if isinstance(sub.typ, StructT) and self.expr.attr in sub.typ.member_types: - return get_element_ptr(sub, self.expr.attr) + sub = Expr(self.expr.value, self.context).ir_node + # contract type + if isinstance(sub.typ, InterfaceT): + # MyInterface.address + assert self.expr.attr == "address" + sub.typ = typ + return sub + if isinstance(sub.typ, StructT) and self.expr.attr in sub.typ.member_types: + return get_element_ptr(sub, self.expr.attr) def parse_Subscript(self): sub = Expr(self.expr.value, self.context).ir_node From e3c609a235bccecfb5f7b6e4d27bc8a34045e31a Mon Sep 17 00:00:00 2001 From: tserg <8017125+tserg@users.noreply.github.com> Date: Thu, 20 Jul 2023 16:42:10 +0800 Subject: [PATCH 2/6] add test --- tests/parser/syntax/test_structs.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/parser/syntax/test_structs.py b/tests/parser/syntax/test_structs.py index b30f7e6098..1f66a47911 100644 --- a/tests/parser/syntax/test_structs.py +++ b/tests/parser/syntax/test_structs.py @@ -575,6 +575,30 @@ def get_y() -> int128: def foo(): bar: C = C({a: 1, b: block.timestamp}) """, + """ +struct X: + balance: uint256 + codesize: uint256 + is_contract: bool + codehash: bytes32 + code: Bytes[32] + +@external +def foo(): + x: X = X({ + balance: 123, + codesize: 456, + is_contract: False, + codehash: empty(bytes32), + code: empty(Bytes[32]) + }) + + a: uint256 = x.balance + b: uint256 = x.codesize + c: bool = x.is_contract + d: bytes32 = x.codehash + e: Bytes[32] = x.code + """, ] From 7bccc0a64366610ed3897c2f588c4e29c51f4a4e Mon Sep 17 00:00:00 2001 From: tserg <8017125+tserg@users.noreply.github.com> Date: Thu, 20 Jul 2023 16:47:56 +0800 Subject: [PATCH 3/6] remove outdated test --- tests/parser/syntax/test_enum.py | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/tests/parser/syntax/test_enum.py b/tests/parser/syntax/test_enum.py index 9bb74fb675..82a1ce6a95 100644 --- a/tests/parser/syntax/test_enum.py +++ b/tests/parser/syntax/test_enum.py @@ -45,19 +45,6 @@ STAFF ADMIN -@external -def foo(x: Roles) -> bool: - return x in [Roles.USER, Roles.ADMIN] - """, - TypeMismatch, - ), - ( - """ -enum Roles: - USER - STAFF - ADMIN - @external def foo(x: Roles) -> Roles: return x.USER # can't dereference on enum instance From c2f672436cc64f943d406e4e006eaffdad4ad5dc Mon Sep 17 00:00:00 2001 From: tserg <8017125+tserg@users.noreply.github.com> Date: Thu, 20 Jul 2023 16:48:30 +0800 Subject: [PATCH 4/6] revert --- tests/parser/syntax/test_enum.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/parser/syntax/test_enum.py b/tests/parser/syntax/test_enum.py index 82a1ce6a95..9bb74fb675 100644 --- a/tests/parser/syntax/test_enum.py +++ b/tests/parser/syntax/test_enum.py @@ -45,6 +45,19 @@ STAFF ADMIN +@external +def foo(x: Roles) -> bool: + return x in [Roles.USER, Roles.ADMIN] + """, + TypeMismatch, + ), + ( + """ +enum Roles: + USER + STAFF + ADMIN + @external def foo(x: Roles) -> Roles: return x.USER # can't dereference on enum instance From 48fed754174fbb33492a13a373bab16303ddb423 Mon Sep 17 00:00:00 2001 From: tserg <8017125+tserg@users.noreply.github.com> Date: Mon, 30 Dec 2024 15:18:57 +0800 Subject: [PATCH 5/6] Revert "remove else branch" This reverts commit 9de09412c2fa8bd56cf5350c3d613cb67af2534f. --- vyper/codegen/expr.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/vyper/codegen/expr.py b/vyper/codegen/expr.py index 1f03d8cecf..d637a454bc 100644 --- a/vyper/codegen/expr.py +++ b/vyper/codegen/expr.py @@ -321,17 +321,17 @@ def parse_Attribute(self): "chain.id is unavailable prior to istanbul ruleset", self.expr ) return IRnode.from_list(["chainid"], typ=UINT256_T) - # Other variables - sub = Expr(self.expr.value, self.context).ir_node - # contract type - if isinstance(sub.typ, InterfaceT): - # MyInterface.address - assert self.expr.attr == "address" - sub.typ = typ - return sub - if isinstance(sub.typ, StructT) and self.expr.attr in sub.typ.member_types: - return get_element_ptr(sub, self.expr.attr) + else: + sub = Expr(self.expr.value, self.context).ir_node + # contract type + if isinstance(sub.typ, InterfaceT): + # MyInterface.address + assert self.expr.attr == "address" + sub.typ = typ + return sub + if isinstance(sub.typ, StructT) and self.expr.attr in sub.typ.member_types: + return get_element_ptr(sub, self.expr.attr) def parse_Subscript(self): sub = Expr(self.expr.value, self.context).ir_node From 79ce92efbfdd2574b6af013d0f56dac9e57fb370 Mon Sep 17 00:00:00 2001 From: tserg <8017125+tserg@users.noreply.github.com> Date: Thu, 20 Feb 2025 11:48:52 +0800 Subject: [PATCH 6/6] fix syntax --- tests/functional/syntax/test_structs.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/functional/syntax/test_structs.py b/tests/functional/syntax/test_structs.py index 335d066c71..c3fc9e5bfe 100644 --- a/tests/functional/syntax/test_structs.py +++ b/tests/functional/syntax/test_structs.py @@ -585,13 +585,13 @@ def foo(): @external def foo(): - x: X = X({ - balance: 123, - codesize: 456, - is_contract: False, - codehash: empty(bytes32), - code: empty(Bytes[32]) - }) + x: X = X( + balance=123, + codesize=456, + is_contract=False, + codehash=empty(bytes32), + code=empty(Bytes[32]) + ) a: uint256 = x.balance b: uint256 = x.codesize