Skip to content

too eager widening of singleton types #102

@scabug

Description

@scabug

I expected the following code to compile:

trait Foo {
  type Arg
  type Prod
  def makeProd(a : Arg): Prod
}

// simulate dependent method types
case class buildProd(foo: Foo) {
  def apply(a: foo.Arg): foo.Prod = foo.makeProd(a)
}

object main {
  val myFoo = new Foo{type Arg=Int; type Prod=(Int, Int); def makeProd(i: Int) = (i, i)}
  
  buildProd(myFoo)(1)
}

Instead, the compiler complains:

15: error: method apply cannot be accessed in buildProd
 because its instance type (Foo#Arg)Foo#Prod contains a malformed type: Foo#Arg
  buildProd(myFoo)(1)
           ^
one error found

It seems foo.type gets approximated to Foo too early..

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions