Skip to content

Implicits are resolved circularly when extending a class with an implicit parameter and field #16581

Open
@coreywoodfield

Description

@coreywoodfield

Compiler version

3.2.1

Minimized code

import scala.reflect.ClassTag

abstract class Companion[C](implicit val ct: ClassTag[C])

case class Impl()
object Impl extends Companion[Impl]

Output

-- Error: Test.scala:7:35 -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
7 |object Impl extends Companion[Impl]
  |                                   ^
  |                                   super constructor cannot be passed a self reference Impl.ct unless parameter is declared by-name
1 error found

Expectation

It's trying to use Impl.ct as the implicit value to pass to the super constructor, but that obviously doesn't work. I would expect this to get the implicit ClassTag from wherever implicit ClassTags are normally gotten from. This works fine in scala 2. Removing the val also fixes it, but then you don't have the ClassTag field

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:transformbacklogNo work planned on this by the core team for the time being.itype:bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions