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 with option field (fix #19419) #19434

Merged
merged 1 commit into from
Sep 24, 2023

Conversation

yuyi98
Copy link
Member

@yuyi98 yuyi98 commented Sep 24, 2023

This PR fix interface with option field (fix #19419).

  • Fix interface with option field.
  • Add test.
import time

interface InterfaceObject {
mut:
	duration ?time.Duration
	update()
}

struct Object {
mut:
	duration ?time.Duration
}

fn (mut obj Object) update() {
	duration := obj.duration or { time.second }
	println(duration)
}

struct FooObject {
	Object
}

fn (mut obj FooObject) update() {
	duration := obj.duration or { time.millisecond * 500 }
	println(duration)
}

fn main() {
	mut object := InterfaceObject(FooObject{})
	println(object)
	assert '${object.duration}' == 'Option(none)'
}

PS D:\Test\v\tt1> v run .    
InterfaceObject(FooObject{
    Object: Object{
        duration: Option(none)
    }
})

@spytheman spytheman merged commit 28234c7 into vlang:master Sep 24, 2023
46 checks passed
@yuyi98 yuyi98 deleted the fix_embed_struct branch September 25, 2023 00:45
Wertzui123 pushed a commit to Wertzui123/v that referenced this pull request Oct 8, 2023
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 builderr with interfaces that have option fields and embedded structs that implement the interface
2 participants