Skip to content

Commit

Permalink
fix: missing validation on events
Browse files Browse the repository at this point in the history
also update expected exception on some struct failures now that we're
using a common helper function
  • Loading branch information
z80dev committed Sep 30, 2024
1 parent b44e202 commit 81a700c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
3 changes: 2 additions & 1 deletion tests/functional/syntax/test_ann_assign.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from vyper import compiler
from vyper.exceptions import (
InstantiationException,
InvalidAttribute,
TypeMismatch,
UndeclaredDefinition,
Expand Down Expand Up @@ -73,7 +74,7 @@ def foo() -> int128:
def foo() -> int128:
s: S = S(a=1)
""",
VariableDeclarationException,
InstantiationException,
),
(
"""
Expand Down
10 changes: 8 additions & 2 deletions tests/functional/syntax/test_structs.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ def foo():
""",
UnknownAttribute,
),
"""
(
"""
struct A:
x: int128
y: int128
Expand All @@ -41,6 +42,8 @@ def foo():
def foo():
self.a = A(x=1)
""",
InstantiationException,
),
"""
struct A:
x: int128
Expand All @@ -61,7 +64,8 @@ def foo():
def foo():
self.a = A(self.b)
""",
"""
(
"""
struct A:
x: int128
y: int128
Expand All @@ -70,6 +74,8 @@ def foo():
def foo():
self.a = A({x: 1})
""",
InstantiationException,
),
"""
struct C:
c: int128
Expand Down
8 changes: 8 additions & 0 deletions vyper/semantics/types/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from vyper.exceptions import (
EventDeclarationException,
FlagDeclarationException,
InstantiationException,
NamespaceCollision,
StructureException,
UnfoldableNode,
Expand Down Expand Up @@ -284,6 +285,13 @@ def from_EventDef(cls, base_node: vy_ast.EventDef) -> "EventT":
def _ctor_call_return(self, node: vy_ast.Call) -> None:
# validate keyword arguments if provided
if len(node.keywords) > 0:
if len(node.args) > 0:
raise InstantiationException(
"Event instantiation requires either all keyword arguments "
"or all positional arguments",
node,
)

return validate_kwargs(node, self.arguments.copy(), self.typeclass)

# warn about positional argument depreciation
Expand Down

0 comments on commit 81a700c

Please sign in to comment.