Skip to content

import.{given ?} doesn't work, but probably should #8696

Closed
@neko-kai

Description

@neko-kai

Minimized code

@main def main(): Unit = {
  final case class Item(a: Int)
  object Item {
    extension on (i: Int) {
      def squashWith(l: Iterable[Item]): Int = (List(Item(i))) ++ l).map(_.a).sum
    }
  }
  import Item.{given ?}
  println(5 squashWith List(Item(1), Item(2)))
}

Output

Error:(35, 13) value squashWith is not a member of Int/T, but could be made available as an extension method.
The following import might fix the problem:
  import Item.extension_squashWith_Int.squashWith
         
  println(5 squashWith List(Item(1), Item(2)))

Expectation

Should work. Moreover, if the wildcard is hidden by a type-alias it compiles and works:

  type Xa[A] = A
  import Item.{given Xa[?]} // works now

Motivation

Given import imports givens based on their compatibility with the given type, naturally all types are compatible with the wildcard type, as evidenced by Xa[?] working correctly - it may even be more natural to write than given _ if you look at it from the point of view of syntactical consistency – although I do not advocate for replacement of given _ with given ?.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions