Replies: 8 comments 5 replies
-
Look at this file here for starters: https://github.com/sskeirik/clarity-trait-experiments/blob/master/run-tests.sh |
Beta Was this translation helpful? Give feedback.
-
Here is a trait issue to think about, "allow trait inside of optional": #3179 |
Beta Was this translation helpful? Give feedback.
-
I tired to grab all the trait-related issues here, there were a few more about language design outside of that (e.g. #2921).
|
Beta Was this translation helpful? Give feedback.
-
So, here's an issue to discuss that I found in my trait experiments repo. This contract works:
(use-trait math 'SP8CW062DS1XAZJJXWKSM9EMMDD51BRVFMY8MBX6.math-trait.math)
(define-public (add-call (math-contract <math>) (x uint) (y uint))
(contract-call? math-contract add x y)
)
(define-public (add-call-indirect (math-contract <math>) (x uint) (y uint))
(let ((new-math-contract math-contract))
(add-call new-math-contract x y)
)
) But this contract doesn't work:
(use-trait math 'SP8CW062DS1XAZJJXWKSM9EMMDD51BRVFMY8MBX6.math-trait.math)
(define-public (sub-call (math-contract <math>) (x uint) (y uint))
(let ((new-math-contract math-contract))
(contract-call? new-math-contract sub x y)
)
) So, after the call today, my understanding is that trait-likeness is supposed to be dropped after a let-renaming. However, the checker still lets it be used as a parameter to a trait-valued function. For consistency, I think that |
Beta Was this translation helpful? Give feedback.
-
I have another example from the trait experiments repo that I'm unsure of. The checker accepts this contract:
(use-trait empty 'SP8CW062DS1XAZJJXWKSM9EMMDD51BRVFMY8MBX6.empty-trait.empty)
(use-trait empty-copy 'SP8CW062DS1XAZJJXWKSM9EMMDD51BRVFMY8MBX6.empty-trait.empty)
(define-public (use-empty (empty-contract <empty>))
(ok true)
)
(define-public (use-empty-copy (empty-contract <empty-copy>))
(use-empty empty-contract)
) This contract uses the same trait twice but with a different name and then the checker allows those two trait aliases to be used interchangeably. EDIT: I am happy to file an issue on this too if this is not the intended behavior. |
Beta Was this translation helpful? Give feedback.
-
For trait-checking and dynamic invocation, here would be a proposed set of changes that would make traits behave more coherently and less surprisingly to trait users:
This should result in the following semantics:
|
Beta Was this translation helpful? Give feedback.
-
Can we also explore the other path, fully embracing a trait as a type? The related pain points that I've seen for developers are:
(1) is not doable while maintaining the ability to do complete static analysis on a contract call without state info, but (2) seems reasonable. The let-binding discussed above seems to fall into the same category of functionality as (2). (2) should come naturally if trait is treated as a type, but there may be some problems with the current implementation that could be addressed. |
Beta Was this translation helpful? Give feedback.
-
Perhaps this is an opportunity to make traits a refinement type of principal, as proposed in clarity-lang/reference#24 |
Beta Was this translation helpful? Give feedback.
-
TBD -- we got issues. Need a full specification and test battery.
Beta Was this translation helpful? Give feedback.
All reactions