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 array contains method with interface(fix #19670) #19675

Merged
merged 2 commits into from Oct 29, 2023

Conversation

shove70
Copy link
Contributor

@shove70 shove70 commented Oct 27, 2023

  1. Fix cgen error: cannot convert 'struct string *' to 'struct string' #19670
  2. Add tests.
interface Param {}

const some_strings = ['one', 'two', 'three']

fn test(params ...Param) {
	param := params[0]
	match param {
		string {
			if param in some_strings {
				println('in some_strings')
			}
		}
		else {
			panic('oops')
		}
	}
}

fn main() {
	test('three')
}

outputs:

in some_strings

@spytheman
Copy link
Member

Please rebase over master.

@shove70
Copy link
Contributor Author

shove70 commented Oct 27, 2023

Please rebase over master.

OK, it's not fixed yet, I'll rebase it when I fix it. ❤️

@spytheman
Copy link
Member

This still fails:

interface Param {}

fn test_is_string_in_array() {
	param := Param('three')
	if param is string {
		if param in ['one', 'two', 'three'] {
			assert true
		} else {
			assert false
		}
	}
}

@spytheman spytheman merged commit 0148914 into vlang:master Oct 29, 2023
53 checks passed
@shove70 shove70 deleted the array_in_ptr branch October 29, 2023 12:18
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.

cgen error: cannot convert 'struct string *' to 'struct string'
2 participants