Skip to content

Indexing is broken for literals #39

Description

@kenbot

When a literal is interpolated in an index position, the type is overspecialised to the exact literal instance type (Int(1), String("abc"), Char('a') etc), rather than the expected type (Int, String. Char).

I believe the problem lies in the code that parses the implicit monocle.function.Index[S,I,A] instance.

Example:

scala> val x = Map("a" -> 1, "b" -> 2, "c" -> 3)
x: scala.collection.immutable.Map[String,Int] = Map(a -> 1, b -> 2, c -> 3)

scala> get"$x[${"a"}]"
<console>:29: error: No implicit monocle.function.Index[scala.collection.immutable.Map[String,Int], String("a"), _] found to support '[]' indexing

scala> get"$x[${"a": String}]"
res27: Option[Int] = Some(1)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions