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 interface casting in anon fn (fix #23530) #23533

Merged
merged 2 commits into from
Jan 20, 2025

Conversation

yuyi98
Copy link
Member

@yuyi98 yuyi98 commented Jan 20, 2025

This PR fix interface casting in anon fn (fix #23530).

  • Fix interface casting in anon fn.
  • Add test.
@[heap]
struct Foo {
mut:
	val int
}

@[heap]
struct Bar {
mut:
	val int
}

interface FooBar {
mut:
	val int
}

fn main() {
	mut fbs := []&FooBar{}
	fbs << &Foo{1}
	do_something := fn [mut fbs] () {
		_ := fbs.last() as Foo // this line works outside of anon fn
	}
	do_something()
        assert true
}

PS D:\Test\v\tt1> v run .

Copy link

Connected to Huly®: V_0.6-21961

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.

Excellent work.

@spytheman spytheman merged commit 6d40bb8 into vlang:master Jan 20, 2025
72 checks passed
@yuyi98 yuyi98 deleted the fix_interface_as_cast branch January 20, 2025 09:32
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.

C error on arr.last() as Type inside anon fn
2 participants