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

cgen: fix auto deref for interface variable #19841

Merged
merged 8 commits into from
Nov 14, 2023

Conversation

felipensp
Copy link
Member

@felipensp felipensp commented Nov 11, 2023

Fix #19834

🤖 Generated by Copilot at 76cc728

Fix bugs in casting interface variables to strings in cgen.v, if.v, and infix.v. Add a new field and a helper function to handle interface variable dereferencing in different contexts.

🤖 Generated by Copilot at 76cc728

  • Add a new function is_interface_var to simplify checking interface variables (link)
  • Fix casting interface variables to strings in if conditions and infix expressions by setting and restoring the inside_casting_to_str field of the Gen struct (link, link)
  • Use the is_interface_var function to simplify and fix the condition for writing a * before the object name in the gen_call_expr method in cgen.v (link)

@felipensp felipensp marked this pull request as ready for review November 13, 2023 15:17
Copy link
Member

@spytheman spytheman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work.

@spytheman
Copy link
Member

@felipensp can you please also take care of that:
image

./v -cstrict -cc clang x_test.v, where x_test.v is:

interface Param {}

fn test_main() {
        param := Param(false)
        match param {
                bool {
                        if param {
                                dump(param) // switching the dump and the println makes it compile
                                println(param)
                        }
                }
                else {}
        }
}

@felipensp
Copy link
Member Author

@felipensp can you please also take care of that: image

Done. Thanks.

@medvednikov medvednikov merged commit 51efe04 into vlang:master Nov 14, 2023
54 checks passed
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.

Empty interface matches bool properly but doesn't evaluate correctly
3 participants