Skip to content

Context bound behaves differently from a using-clause #20070

Closed
@dkz

Description

@dkz

Compiler version

3.3.1, 3.4.1

Minimized code

trait F[A]
given F[Int] = new F {}
def f[A: F] = { (x: A) => x }
println(f[Int](1))

Output

  |f[Int](1)
  |       ^
  |       Found:    (1 : Int)
  |       Required: F[Int]
  |
  | longer explanation available when compiling with `-explain`

Expectation

Scala 3 Book suggests that context bound de-sugaring mirrors the following code:

def f[A](using F[A]) = { (x: A) => x }

Yet, the latter doesn't lead to a compile error in f[Int](1).

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:implicitsrelated to implicitsarea:reportingError reporting including formatting, implicit suggestions, etcitype:bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions