-
-
Notifications
You must be signed in to change notification settings - Fork 836
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]: infer expected types #3765
base: master
Are you sure you want to change the base?
feat[lang]: infer expected types #3765
Conversation
@@ -35,9 +35,9 @@ | |||
|
|||
def validate_index_type(self, node): | |||
# TODO: break this cycle | |||
from vyper.semantics.analysis.utils import validate_expected_type | |||
from vyper.semantics.analysis.utils import infer_type |
Check notice
Code scanning / CodeQL
Cyclic import Note
vyper.semantics.analysis.utils
too hard to evalulate changes until it's rebased on the module work |
it also tags the node with the inferred type
c33e768
to
6b9fff2
Compare
allow conversion from Bytes/String types to shorter length types, e.g. convert `Bytes[20]` to `Bytes[19]` this will become important when we want to allow generic bytestrings inside the type system (`Bytes[...]`) which can only be user-instantiated by converting to a known length.
get_exact_type_from_node, | ||
validate_expected_type, | ||
) | ||
from vyper.semantics.analysis.utils import check_modifiability, get_exact_type_from_node, infer_type |
Check notice
Code scanning / CodeQL
Cyclic import Note
vyper.semantics.analysis.utils
test code: ``` interface Foo: def foo(xs: Bytes[...]) -> uint256: view def bar() -> Bytes[...]: view def baz(xs: Bytes[...]): nonpayable def qux() -> Bytes[...]: nonpayable @external def foo(f: Foo): xs: Bytes[10] = b"" t: uint256 = staticcall f.foo(xs) xs = convert(staticcall f.bar(), Bytes[10]) extcall f.baz(xs) extcall f.qux() ```
255f95f
to
a7556d8
Compare
test code: ``` interface Foo: def foo(xs: Bytes[...]) -> uint256: view def bar() -> Bytes[...]: view def baz(xs: Bytes[...]): nonpayable def qux() -> Bytes[...]: nonpayable @external def foo(f: Foo): xs: Bytes[10] = b"" t: uint256 = staticcall f.foo(xs) xs = staticcall f.bar() extcall f.baz(xs) extcall f.qux() x: Bytes[10] = extcall f.qux() ```
@@ -27,8 +27,8 @@ | |||
from vyper.semantics.analysis.utils import ( | |||
check_modifiability, | |||
get_exact_type_from_node, | |||
infer_type, |
Check failure
Code scanning / CodeQL
Module-level cyclic import Error
vyper.semantics.analysis.utils
vyper.semantics.types.function
definition
import
@@ -14,14 +14,14 @@ | |||
from vyper.semantics.analysis.utils import ( | |||
check_modifiability, | |||
get_exact_type_from_node, | |||
validate_expected_type, | |||
infer_type, |
Check failure
Code scanning / CodeQL
Module-level cyclic import Error
vyper.semantics.analysis.utils
vyper.semantics.types.module
definition
import
@@ -127,7 +127,7 @@ | |||
|
|||
def validate_index_type(self, node): | |||
# TODO break this cycle | |||
from vyper.semantics.analysis.utils import validate_expected_type | |||
from vyper.semantics.analysis.utils import infer_type |
Check notice
Code scanning / CodeQL
Cyclic import Note
vyper.semantics.analysis.utils
validate_expected_type, | ||
validate_kwargs, | ||
) | ||
from vyper.semantics.analysis.utils import check_modifiability, infer_type, validate_kwargs |
Check failure
Code scanning / CodeQL
Module-level cyclic import Error
vyper.semantics.analysis.utils
vyper.semantics.types.user
definition
import
validate_expected_type, | ||
validate_kwargs, | ||
) | ||
from vyper.semantics.analysis.utils import check_modifiability, infer_type, validate_kwargs |
Check failure
Code scanning / CodeQL
Module-level cyclic import Error
vyper.semantics.analysis.utils
vyper.semantics.types.user
definition
import
validate_expected_type, | ||
validate_kwargs, | ||
) | ||
from vyper.semantics.analysis.utils import check_modifiability, infer_type, validate_kwargs |
Check failure
Code scanning / CodeQL
Module-level cyclic import Error
What I did
rework
validate_expected_type
so that it returns (and tags) the expected type instead of just validating the type. this makes it so certain calls tovalidate_expected_type()
can get a concrete type, where previously the type was not known beforehand.this is a language change, generic bytes types (like from an interface) should work more as expected now.
How I did it
How to verify it
Commit message
Commit message for the final, squashed PR. (Optional, but reviewers will appreciate it! Please see our commit message style guide for what we would ideally like to see in a commit message.)
Description for the changelog
Cute Animal Picture