Skip to content

Passing new instance when singleton type is expected should result in type error #2142

Closed
@gsps

Description

@gsps
object Foo {

class A
val a1 = new A()
val a2 = new A()

def f(x: A, y: x.type) = ()
f(a1, a1)           // ok
f(a1, a2)           // error (as expected)
f(new A(), new A()) // error (*** but passes unexpectedly)
f(new A(), a1)      // error (*** but passes unexpectedly)

def g(x: A)(y: x.type) = ()
g(a1)(a1)           // ok
g(a1)(a2)           // error (as expected)
g(new A())(new A()) // error (*** but passes unexpectedly)
g(new A())(a1)      // error (*** but passes unexpectedly)

}

Note that while this also affects the version featuring dependencies within a single parameter group (f() above), the problem seems to be independent of the recent PR #2079: The problem with g() existed even in commits before #2079 was merged.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions