Skip to content

Cannot define a path-dependent Conversion instance #7412

Open
@neko-kai

Description

@neko-kai

minimized code

class Named[S <: String with Singleton](s: S)

object Named {
  given Conversion[(s: String), Named[s.type]] {
    def apply(s: String): Named[s.type] = new Named(s)
  }

  // this is ok:
  // implicit def convert(s: String): Named[s.type] = new Named[s.type](s)

  "abc": Named["abc"]
}

expectation

Expected being able to define an instance of Conversion equivalent to implicit def convert(s: String): Named[s.type]. However the definition above fails to parse!

[error] example.scala:22:20: an identifier expected, but '(' found
[error]   given Conversion[(s: String), Named[s.type]] {
[error]                    ^
[error] example.scala:28:3: Found:    String("abc")
[error] Required: Named[String("abc")]
[error]   "abc": Named["abc"]
[error]   ^
[error] two errors found

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