Skip to content

Interaction between path-dependent types and default args fails to compile #23952

@jbwheatley

Description

@jbwheatley

Compiler version

3.7.0-3.7.3, 3.8.0-RC1-bin-20250819-1f13619-NIGHTLY

(Compiles on 3.6.4)

Minimized code

trait Typeclass[I] sealed trait Enumm { type Insider } object Enumm { case object Enumm1 extends Enumm { case class Insider() object Insider { given t: Typeclass[Insider] = new Typeclass[Insider] {} } } } class Foo implicit val f: Foo = new Foo def pathDependentTypeDefaultParam(tpe: Enumm)(i: tpe.Insider, p: Int = 0)(using t: Typeclass[tpe.Insider]): Int = p def defaultParamNotPDT(tpe: Enumm)(i: tpe.Insider, p: Int = 0)(using t:Foo): Int = p def pathDependentTypeDefaultParamOwnList(tpe: Enumm)(i: tpe.Insider)(p: Int = 0)(using t: Typeclass[tpe.Insider]): Int = p def main = { //doesn't compile //Error: No given instance of type Nothing & Typeclass[? <: Enumm.Enumm1#Insider] was found for parameter t of method foo pathDependentTypeDefaultParam(Enumm.Enumm1)(Enumm.Enumm1.Insider()) //compiles if default arg given explicitly pathDependentTypeDefaultParam(Enumm.Enumm1)(Enumm.Enumm1.Insider(), p = 0) //compiles if using non-path-dependent given defaultParamNotPDT(Enumm.Enumm1)(Enumm.Enumm1.Insider()) //with default args in own parameter list again doesn't compile //Error: No given instance of type Nothing & Typeclass[? <: Enumm.Enumm1#Insider] was found for parameter t of method foo3 pathDependentTypeDefaultParamOwnList(Enumm.Enumm1)(Enumm.Enumm1.Insider())() //again, compiles if default arg given explicitly pathDependentTypeDefaultParamOwnList(Enumm.Enumm1)(Enumm.Enumm1.Insider())(p = 0) } 

Output

[error] -- [E172] Type Error: /Users/jackwheatley/work/37test/src/main/scala/main.scala:29:69 [error] 29 | pathDependentTypeDefaultParam(Enumm.Enumm1)(Enumm.Enumm1.Insider()) [error] | ^ [error] |No given instance of type Nothing & Typeclass[? <: Enumm.Enumm1#Insider] was found for parameter t of method pathDependentTypeDefaultParam [error] -- [E172] Type Error: /Users/jackwheatley/work/37test/src/main/scala/main.scala:39:78 [error] 39 | pathDependentTypeDefaultParamOwnList(Enumm.Enumm1)(Enumm.Enumm1.Insider())() [error] | ^ [error] |No given instance of type Nothing & Typeclass[? <: Enumm.Enumm1#Insider] was found for parameter t of method pathDependentTypeDefaultParamOwnList [error] two errors found 

Expectation

The above code compiles in 3.6.4. Default arguments shouldn't affect implicit resolution.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions