Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
gsps opened this issue Mar 26, 2017 · 1 comment
Closed

Comments

@gsps
Copy link
Contributor

gsps commented Mar 26, 2017

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.

@odersky
Copy link
Contributor

odersky commented Mar 27, 2017

Yes, I think a test is missing that if there is a dependency, the actual parameter type is a singleton type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants