fthomas / fthomas/refined

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

Open
#1,153 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Scala
Stars
1.7k
Forks
152
Avg merge
1h 20m
Merged PRs (30d)
6

Description

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:

```scala
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:

```scala
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:

```scala
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?

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the Scala reproducer in issue #1153, comparing Map("1" -> "foobar") with Map(("1", "foobar")) using refined.auto and NonEmptyString. Determine whether arrow syntax should support the same refinement as tuple syntax; completion requires a confirmed explanation and a regression check or clear documented behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
scala
Domain
developer-experience
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.