-
-
Notifications
You must be signed in to change notification settings - Fork 804
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
feat[lang]: add module.__at__()
to cast to interface
#4090
feat[lang]: add module.__at__()
to cast to interface
#4090
Conversation
allow `module.__interface__` to be used in call position by adding it to the module membership data structure. additionally, fix a bug where interfaces defined inline could not be exported. this is simultaneously fixed as a related bug because previously, interfaces could come up in export analysis as `InterfaceT` or `TYPE_T` depending on their provenance. this commit fixes the bug by making them `TYPE_T` in both imported and inlined provenance. refactor: - wrap interfaces in TYPE_T - streamline an `isinstance(t, (VyperType, TYPE_T))` check. `TYPE_T` now inherits from `VyperType`, so it doesn't need to be listed separately
there was a test for unimplemented `.vyi` interfaces, this commit adds a test for unimplemented inline interface for completeness
we allow for exporting a module with no external functions - i think we should raise in such case: # main.vy
import lib1
def f(x: Bytes[32*5]) -> uint256:
k: uint256 = lib1.foo()
return k
exports: lib1.__interface__
# lib1.vy
@internal
def foo() -> uint256:
return 1 |
import lib1
uses: lib1
@deploy
def __init__():
lib1.__interface__(self).__init__()
exports: lib1.__interface__
#lib1.vy
k: uint256
@external
def bar():
pass
@deploy
def __init__():
self.k = 10
|
main.vy
import lib1
#uses: lib1
@deploy
def __init__():
log lib1.__interface__.Foo(1)
s: lib1.Structt = lib1.__interface__.Structt(i=1)
exports: lib1.__interface__
#lib1.vy
event Foo:
i: uint256
struct Structt:
i: uint256
k: uint256
@external
def bar():
pass
@deploy
def __init__():
self.k = 10 |
should address #3943, right? |
with
# main.vy
import lib1
@external
def foo() -> uint256:
return staticcall lib1.__interface__(self).d()
# lib1.vy
d: public(uint256) |
would it be too much to ask for implicit cast of
|
on latest (9621397) we get:
|
yes but it's a bit hairy. it will feel ambiguous once we add |
|
yes. updated the PR description |
@@ -19,7 +19,7 @@ | |||
) | |||
from vyper.semantics.data_locations import DataLocation | |||
from vyper.semantics.types.base import TYPE_T, VyperType, is_type_t | |||
from vyper.semantics.types.function import ContractFunctionT | |||
from vyper.semantics.types.function import ContractFunctionT, MemberFunctionT |
Check failure
Code scanning / CodeQL
Module-level cyclic import Error
vyper.semantics.types.function
vyper.semantics.types.module
definition
import
'ContractFunctionT' may not be defined if module
vyper.semantics.types.function
vyper.semantics.types.module
definition
import
@@ -19,7 +19,7 @@ | |||
) | |||
from vyper.semantics.data_locations import DataLocation | |||
from vyper.semantics.types.base import TYPE_T, VyperType, is_type_t | |||
from vyper.semantics.types.function import ContractFunctionT | |||
from vyper.semantics.types.function import ContractFunctionT, MemberFunctionT |
Check failure
Code scanning / CodeQL
Module-level cyclic import Error
vyper.semantics.types.function
vyper.semantics.types.module
definition
import
'MemberFunctionT' may not be defined if module
vyper.semantics.types.function
vyper.semantics.types.module
definition
import
…face-intrinsic feat[test]: add tests for intrinsic interfaces
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #4090 +/- ##
===========================================
- Coverage 91.40% 47.70% -43.71%
===========================================
Files 112 112
Lines 15927 16028 +101
Branches 2694 2699 +5
===========================================
- Hits 14558 7646 -6912
- Misses 935 7749 +6814
- Partials 434 633 +199 ☔ View full report in Codecov by Sentry. 🚨 Try these New Features:
|
# lib1.vy
def doo():
pass
# main.vy
import lib1
i: public(lib1.__interface__)
@external
def boo():
pass
exports: self.i
|
module.__at__
to cast to interface
module.__at__
to cast to interfacemodule.__at__()
to cast to interface
What I did
fixes #3943, #3959
How I did it
How to verify it
Commit message
Description for the changelog
Cute Animal Picture