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

Creating a Map of Literal Refined Types as the Key doesn't work #1153

Open
bcarter97 opened this issue Feb 22, 2023 · 1 comment
Open

Creating a Map of Literal Refined Types as the Key doesn't work #1153

bcarter97 opened this issue Feb 22, 2023 · 1 comment

Comments

@bcarter97
Copy link

bcarter97 commented Feb 22, 2023

Hi, I've noticed if I try to create a Map with the key as a Refined Type and instantiate it with a literal, the compiler gives an error:

import eu.timepit.refined.auto._
import eu.timepit.refined.types.all.NonEmptyString

val bar: Map[NonEmptyString, NonEmptyString] = Map("1" -> "foobar")
/*
found   : (String, String)
required: (eu.timepit.refined.types.all.NonEmptyString, eu.timepit.refined.types.all.NonEmptyString)
*/

I can change to just the value as a Refined type and it works as expected:

import eu.timepit.refined.auto._
import eu.timepit.refined.types.all.NonEmptyString

val bar: Map[String, NonEmptyString] = Map("1" -> "foobar")
// val bar: Map[String,eu.timepit.refined.types.all.NonEmptyString] = Map(1 -> foobar)

I can also create a Map out Tuples which works:

import eu.timepit.refined.auto._
import eu.timepit.refined.types.all.NonEmptyString

val bar: Map[NonEmptyString, NonEmptyString] = Map(("1", "foobar"))
// val bar: Map[eu.timepit.refined.types.all.NonEmptyString,eu.timepit.refined.types.all.NonEmptyString] = Map(1 -> foobar)

So it looks like the Arrow syntax is causing this - is this intended behaviour?

@fthomas
Copy link
Owner

fthomas commented Feb 26, 2023

So it looks like the Arrow syntax is causing this - is this intended behaviour?

Not intended but expected at least. The arrow syntax is an implicit conversion and the automatic refinement is an implicit conversion but Scala won't chain them so that your first snippet typechecks.

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