Skip to content
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

Draft
wants to merge 21 commits into
base: master
Choose a base branch
from

Conversation

charles-cooper
Copy link
Member

@charles-cooper charles-cooper commented Feb 9, 2024

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 to validate_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

Put a link to a cute animal picture inside the parenthesis-->

vyper/utils.py Fixed Show fixed Hide fixed
vyper/utils.py Fixed Show fixed Hide fixed
vyper/utils.py Fixed Show fixed Hide fixed
@@ -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

Import of module
vyper.semantics.analysis.utils
begins an import cycle.
@@ -125,15 +125,15 @@

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

Import of module
vyper.semantics.analysis.utils
begins an import cycle.
@@ -16,7 +16,7 @@
)
from vyper.semantics.analysis.base import Modifiability
from vyper.semantics.analysis.levenshtein_utils import get_levenshtein_error_suggestions
from vyper.semantics.analysis.utils import check_modifiability, validate_expected_type
from vyper.semantics.analysis.utils import check_modifiability, infer_type

Check notice

Code scanning / CodeQL

Cyclic import Note

Import of module
vyper.semantics.analysis.utils
begins an import cycle.
@fubuloubu
Copy link
Member

too hard to evalulate changes until it's rebased on the module work

@charles-cooper charles-cooper force-pushed the feat/infer_expected_types branch from c33e768 to 6b9fff2 Compare February 10, 2024 16:43
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

Import of module
vyper.semantics.analysis.utils
begins an import cycle.
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

Import of module
vyper.semantics.analysis.utils
begins an import cycle.
vyper/semantics/analysis/utils.py Fixed Show fixed Hide fixed
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()
```
@charles-cooper charles-cooper force-pushed the feat/infer_expected_types branch from 255f95f to a7556d8 Compare March 15, 2024 19:50
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()
```
@charles-cooper charles-cooper changed the title feat: infer expected types feat[lang]: infer expected types Mar 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants