Skip to content

Commit 4efae6d

Browse files
fix[lang]: disallow @raw_return in interfaces (#4700)
this commit disallows `@raw_return` in `.vyi` files, as the decorator doesn't have much semantic information for interfaces.
1 parent 6b5a7e1 commit 4efae6d

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

tests/functional/codegen/features/decorators/test_raw_return.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from vyper.compiler import compile_code
55
from vyper.evm.opcodes import version_check
6-
from vyper.exceptions import StructureException
6+
from vyper.exceptions import FunctionDeclarationException, StructureException
77
from vyper.utils import method_id
88

99

@@ -169,8 +169,8 @@ def test_interfaces_fail(bad_code, exc):
169169
compile_code(bad_code)
170170

171171

172-
def test_raw_return_interface(env, get_contract, make_input_bundle):
173-
# interface with @raw_return decorator
172+
def test_raw_return_not_allowed_in_interface(make_input_bundle):
173+
# interface with @raw_return decorator should fail
174174
iface = """
175175
@external
176176
@raw_return
@@ -188,11 +188,11 @@ def foo() -> Bytes[32]:
188188
return b''
189189
"""
190190
input_bundle = make_input_bundle({"iface.vyi": iface})
191-
c = get_contract(main, input_bundle=input_bundle)
192191

193-
# does abi-decoding
194-
res = c.foo()
195-
assert res == b""
192+
with pytest.raises(FunctionDeclarationException) as e:
193+
compile_code(main, input_bundle=input_bundle)
194+
195+
assert e.value._message == "`@raw_return` not allowed in interfaces"
196196

197197

198198
# test raw_return from storage, transient, constant and immutable

vyper/semantics/types/function.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,11 @@ def from_vyi(cls, funcdef: vy_ast.FunctionDef) -> "ContractFunctionT":
340340
# guaranteed by parse_decorators and disallowing nonreentrant pragma
341341
assert decorators.reentrant_node is None # sanity check
342342

343+
if decorators.raw_return_node is not None:
344+
raise FunctionDeclarationException(
345+
"`@raw_return` not allowed in interfaces", decorators.raw_return_node
346+
)
347+
343348
# it's redundant to specify visibility in vyi - always should be external
344349
function_visibility = decorators.visibility
345350
if function_visibility is None:

0 commit comments

Comments
 (0)