Skip to content

Fix #1463: no type cast in singelton equality test #2988

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
wants to merge 1 commit into from

Conversation

liufengyun
Copy link
Contributor

Fix #1463: no type cast in singelton equality test


def f0(x: Any) = x match { case Bob2 => Bob2 } // class cast exception at runtime, dotc only
def f1(x: Any) = x match { case Bob => Bob } // class cast exception at runtime, dotc only
def f2(x: Any): Bob.type = x match { case x @ Bob => x } // class cast exception at runtime, dotc and javac.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not typecheck because x in the right hand side should have type Any, not Bob.type, as explained in my comment: #1463 (comment)
This matches the behavior of scalac with -Xfuture.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @smarter , I see both approaches may cause some confusion to programmers. We need a spec here, are you happy with what's in -Xfuture in 2.11 and 2.12, @odersky ?

@liufengyun liufengyun force-pushed the fix-1463 branch 2 times, most recently from e5f0709 to f2b453a Compare August 18, 2017 14:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants