Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: mutability check for interface implements #3805

Merged
merged 7 commits into from
Feb 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/tokens/ERC1155ownable.vy
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ def setContractURI(contractUri: String[MAX_URI_LENGTH]):
self.contractURI = contractUri
log URI(contractUri, 0)

@pure
@view
@external
def supportsInterface(interfaceId: bytes4) -> bool:
"""
Expand Down
2 changes: 1 addition & 1 deletion examples/tokens/ERC721.vy
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def __init__():
self.baseURL = "https://api.babby.xyz/metadata/"


@pure
@view
@external
def supportsInterface(interface_id: bytes4) -> bool:
"""
Expand Down
44 changes: 44 additions & 0 deletions tests/functional/syntax/test_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,50 @@ def approve(_spender : address, _value : uint256) -> bool:
""",
InterfaceViolation,
),
(
# `payable` decorator not implemented
"""
interface testI:
def foo() -> uint256: payable

implements: testI

@external
def foo() -> uint256:
return 0
""",
InterfaceViolation,
),
(
# decorators must be strictly identical
"""
interface Self:
def protected_view_fn() -> String[100]: nonpayable

implements: Self

@external
@pure
def protected_view_fn() -> String[100]:
return empty(String[100])
""",
InterfaceViolation,
),
(
# decorators must be strictly identical
"""
interface Self:
def protected_view_fn() -> String[100]: view

implements: Self

@external
@pure
def protected_view_fn() -> String[100]:
return empty(String[100])
""",
InterfaceViolation,
),
]


Expand Down
5 changes: 1 addition & 4 deletions vyper/semantics/types/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,10 +480,7 @@ def implements(self, other: "ContractFunctionT") -> bool:
if return_type and not return_type.compare_type(other_return_type): # type: ignore
return False

if self.mutability > other.mutability:
return False

return True
return self.mutability == other.mutability

@cached_property
def default_values(self) -> dict[str, vy_ast.VyperNode]:
Expand Down
Loading