Skip to content
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

Unsound subtyping behavior with (=> Any) #1386

Closed
scabug opened this issue Sep 27, 2008 · 5 comments
Closed

Unsound subtyping behavior with (=> Any) #1386

scabug opened this issue Sep 27, 2008 · 5 comments
Assignees

Comments

@scabug
Copy link

scabug commented Sep 27, 2008

The following is correctly disallowed:

scala> def foo(x: Int) = x + 1
foo: (Int)Int

scala> def bar(g: (=>Int) => Int, x: Int) = g(x)
bar: ((=> Int) => Int,Int)Int

scala> bar(foo, 3)
<console>:7: error: type mismatch;
 found   : (Int) => Int
 required: (=> Int) => Int
       bar(foo, 3)
           ^

but at present this seems to work:

scala> def myToString(x : Any) : String = x.toString   
foo: (Any)String

scala> def bar(g:(=>Any) => String, x:Int) = g(x)
bar: ((=> Any) => String,Int)String

scala> bar(myToString, 3)
res13: String = <function>
@scabug
Copy link
Author

scabug commented Sep 27, 2008

Imported From: https://issues.scala-lang.org/browse/SI-1386?orig=1
Reporter: Geoffrey Alan Washburn (washburn)
See #5517

@scabug
Copy link
Author

scabug commented Sep 27, 2008

@odersky said:
I fail to see the unsoundness. (=> Any) is a subtype of Any.

@scabug
Copy link
Author

scabug commented Sep 27, 2008

Geoffrey Alan Washburn (washburn) said:
If (=> Any) is a subtype of Any, then why is (=> Int) not a subtype of Int?

Maybe you didn't look closely enough, but clearly the abstractions are getting violated because in the latter example myToString is receiving some kind of thunk rather than the integer 3 as its argument.

@scabug
Copy link
Author

scabug commented Sep 27, 2008

Aaron Harnly (aaronharnly) said:
Replying to [comment:2 washburn]:

If (=> Any) is a subtype of Any, then why is (=> Int) not a subtype of Int?

Eh? (=> Any) is a subtype of Any in the same sense that (=> Int) is a subtype of Any.

@scabug
Copy link
Author

scabug commented Sep 27, 2008

Geoffrey Alan Washburn (washburn) said:
Replying to [comment:3 aaronharnly]:

Replying to [comment:2 washburn]:

If (=> Any) is a subtype of Any, then why is (=> Int) not a subtype of Int?

Eh? (=> Any) is a subtype of Any in the same sense that (=> Int) is a subtype of Any.

Indeed, I hadn't been thinking about the problem in that fashion.

However, there is still the issue that the abstraction boundaries are getting violated. At least with respect the current description of by-name types/parameters in the specification.

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

2 participants