Skip to content

Commit d6a72b6

Browse files
committed
refactor: log an error for duplicate decorators
1 parent 2dc0650 commit d6a72b6

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

src/puyapy/awst_build/contract.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,6 @@ def visit_function(
296296
if (len(list(filter(None, (subroutine_dec, abimethod_dec, baremethod_dec))))) > 1:
297297
logger.error(
298298
f"ARC-4 contract member functions"
299-
f" (other than __init__ or approval / clear program methods)"
300299
f" must not be annotated with more than one of"
301300
f" @{constants.SUBROUTINE_HINT_ALIAS},"
302301
f" @{constants.ABIMETHOD_DECORATOR_ALIAS},"

src/puyapy/awst_build/utils.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ def get_decorators_by_fullname(
7373

7474
# map alias to canonical name
7575
full_name = DECORATOR_ALIAS_MAPPING.get(full_name, full_name)
76+
77+
if full_name in result:
78+
logger.error("duplicate decorator", location=ctx.node_location(d))
7679
result[full_name] = d
7780
return result
7881

tests/test_expected_output/arc4.test

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -480,17 +480,27 @@ from algopy import arc4, public, subroutine
480480
class MyContract(arc4.ARC4Contract):
481481
@public
482482
@subroutine
483-
def a(self) -> None: ## E: ARC-4 contract member functions (other than __init__ or approval / clear program methods) must not be annotated with more than one of @algopy.subroutine, @algopy.arc4.abimethod, @algopy.public, or @algopy.arc4.baremethod
483+
def a(self) -> None: ## E: ARC-4 contract member functions must not be annotated with more than one of @algopy.subroutine, @algopy.arc4.abimethod, @algopy.public, or @algopy.arc4.baremethod
484484
pass
485485

486486
@arc4.abimethod
487487
@subroutine
488-
def b(self) -> None: ## E: ARC-4 contract member functions (other than __init__ or approval / clear program methods) must not be annotated with more than one of @algopy.subroutine, @algopy.arc4.abimethod, @algopy.public, or @algopy.arc4.baremethod
488+
def b(self) -> None: ## E: ARC-4 contract member functions must not be annotated with more than one of @algopy.subroutine, @algopy.arc4.abimethod, @algopy.public, or @algopy.arc4.baremethod
489489
pass
490490

491491
@arc4.abimethod
492+
@public ## E: duplicate decorator
493+
def c(self) -> None:
494+
pass
495+
496+
@arc4.abimethod
497+
@arc4.abimethod ## E: duplicate decorator
498+
def d(self) -> None:
499+
pass
500+
492501
@public
493-
def c(self) -> None:
502+
@public ## E: duplicate decorator
503+
def e(self) -> None:
494504
pass
495505

496506
## case: bad_signatures

0 commit comments

Comments
 (0)