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

Type of folded constant expression can be ambiguous for user types #3280

Closed
trocher opened this issue Feb 15, 2023 · 1 comment
Closed

Type of folded constant expression can be ambiguous for user types #3280

trocher opened this issue Feb 15, 2023 · 1 comment

Comments

@trocher
Copy link
Contributor

trocher commented Feb 15, 2023

Version Information

  • vyper Version (output of vyper --version): 0.3.8+commit.d76c6ed2
  • OS: OSX
  • Python Version (output of python --version): 3.8.0

What's your issue about?

The type of folded constant expression can be ambiguous when it cannot be inferred prior to typeching. This leads the constant expression to mostly act as a macro.

vyper/vyper/ast/folding.py

Lines 183 to 189 in 187ab0e

try:
type_ = type_from_annotation(node.annotation)
except UnknownType:
# handle user-defined types e.g. structs - it's OK to not
# propagate the type annotation here because user-defined
# types can be unambiguously inferred at typechecking time
pass

For example, the following code compiles while I don't think it should.

struct A:
    a:uint256

b: constant(DynArray[A,1]) = []

@external
def test():
    a:DynArray[uint256,1] = b

How can it be fixed?

I'm not really sure how this could be fixed easily with the current folding design.

@trocher
Copy link
Contributor Author

trocher commented Feb 19, 2024

The issue is no longer there in 4b4e188, the example above fails compilation. Was removed by the refactoring of folding (#3719, #3669)

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

No branches or pull requests

2 participants