Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Using this to get access to a state variable of struct instance causes an bool-type var #15525

Closed
haoyang9804 opened this issue Oct 18, 2024 · 3 comments
Labels

Comments

@haoyang9804
Copy link
Contributor

Description

The line true ? contract0.struct1(true) : this.struct_instance13(); causes an error with the following error message: True expression's type struct contract0.struct1 memory does not match false expression's type bool. I think both sides are of type contract0.struct1.

contract contract0 {
  struct struct1 {
    bool struct_member2;
  }
}

contract contract12 {
  contract0.struct1 public struct_instance13;

  function func14() public view {
    true ? contract0.struct1(true) : this.struct_instance13();
  }
}

Environment

  • Compiler version: 0.8.28-develop.2024.10.7
@haoyang9804
Copy link
Contributor Author

I guess the type system exposes a tuple type including all element types in the struct. For instance, if the struct S has member bool b and int i, then this.S() returns a tuple of type tuple(bool, int). But it seems it happens implicitly. I cannot find references from document about getter function: https://docs.soliditylang.org/en/develop/contracts.html#getter-functions

@haoyang9804
Copy link
Contributor Author

I guess the type system exposes a tuple type including all element types in the struct. For instance, if the struct S has member bool b and int i, then this.S() returns a tuple of type tuple(bool, int). But it seems it happens implicitly. I cannot find references from document about getter function: https://docs.soliditylang.org/en/develop/contracts.html#getter-functions

Based on this assumption, I'd like to help update the document to notify users about this scenario. Can anyone help add a document tag for this issue and remove the bug one?

@cameel
Copy link
Member

cameel commented Oct 18, 2024

This is a long-standing quirk of the language stemming from the fact that ABI-encoding of structs was not defined back when the getter functionality was implemented.

There are multiple issues this could be considered a duplicate of: #14114, #6337, #12863. Especially #6337 - I see that it got closed as stale. I'm going to reopen it and close this one.

In any case, changing it would be breaking. We definitely should have it documented though. It's a very unintuitive behavior.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants