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

checker: fix mismatch checking when a function returns sumtype as an argument(fix #19325) #20264

Merged
merged 1 commit into from
Dec 26, 2023

Conversation

shove70
Copy link
Contributor

@shove70 shove70 commented Dec 25, 2023

  1. Fixed Typecasting / -checking for callback return sumtypes does not work #19325
  2. Add tests.
type Response = int | string

fn my_resp() string {
	return 'hello'
}

fn event(cb fn () Response) {
	resp := cb()
	dump(resp is string)
}

event(my_resp)

outputs:

a.v:12:7: error: cannot use `fn () string` as `fn () Response` in argument 1 to `event`
   10 | }
   11 | 
   12 | event(my_resp)
      |       ~~~~~~~
   13 | 
   14 |

vlib/v/checker/fn.v Outdated Show resolved Hide resolved
vlib/v/gen/c/cgen.v Outdated Show resolved Hide resolved
@shove70
Copy link
Contributor Author

shove70 commented Dec 25, 2023

😆😆😆 Very hacky indeed...... hahahaha

I'll change it to this later:

zz.v:13:7: error: cannot use `fn (string) string` as `fn (Response) Response` in argument 1 to `event`
   11 | }
   12 |
   13 | event(myfn)
      |       ~~~~

@shove70 shove70 changed the title ast, checker, cgen: implement converting return type to sumtype when functions are passed as args(fix #19325) checker: fix mismatch checking when a function returns sumtype as an argument(fix #19325) Dec 26, 2023
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 1aad481 into vlang:master Dec 26, 2023
54 checks passed
@shove70 shove70 deleted the shove-patch-2 branch December 26, 2023 05:05
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.

Typecasting / -checking for callback return sumtypes does not work
2 participants