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

Try overload resolution ambiquity #17

Open
EliasJorgensen opened this issue Mar 13, 2020 · 3 comments
Open

Try overload resolution ambiquity #17

EliasJorgensen opened this issue Mar 13, 2020 · 3 comments

Comments

@EliasJorgensen
Copy link

EliasJorgensen commented Mar 13, 2020

When i use Try.getOrElseThrow, i get the following error:
image

This is the code in question:

val flow = Try { flowDao.save(Flow(source.name, source.applicationId)) }
	.getOrElseThrow { FlowNameAlreadyInUse() }

This is my exception:

@ResponseStatus(HttpStatus.CONFLICT)
class FlowNameAlreadyInUse : RuntimeException()

I am using it the same way that i would throw an exception with java.util.Optional.getOrElseThrow, so i believe this to be a bug.

I can make it work by putting the exception in a lambda, but i believe this to be a bad solution, especially given that IntelliJ keeps suggesting me to remove the useless lambda.

val flow = Try { flowDao.save(Flow(source.name, source.applicationId)) }
	.getOrElseThrow { -> FlowNameAlreadyInUse() }
@mincong-h
Copy link
Member

mincong-h commented May 10, 2020

Hi @EliasJorgensen , I never used Kotlin before and just tried it. It's cool 😎 . I can reproduce the problem (#18). I think this issue should go to vavr core (https://github.com/vavr-io/vavr) because vavr-kotlin is only a wrapper. It seems that Kotlin cannot distinguish function and supplier when the methods are overloaded. For Java Optional, it works because it has only two overloaded methods: orElseThrow() and orElseThrow(Supplier), which are not ambiguous. cc @danieldietrich, @ruslansennov

TL;DR: I think there is no easy and short term solution here

@EliasJorgensen
Copy link
Author

Hi @mincong-h, thanks for checking out my bug report. I'm a bit unsure whether you want me to report the bug in the core repository, as there is no easy "fix"? Let me know and i'll create one 😄

@mincong-h
Copy link
Member

@EliasJorgensen , sorry I was not clear. I think there is nothing to do on your side. Let's wait and see if Daniel, Ruslan, or other members have some thoughts about this.

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

No branches or pull requests

2 participants