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

don't crash on overloaded == #5904

Closed
scabug opened this issue Jun 13, 2012 · 3 comments
Closed

don't crash on overloaded == #5904

scabug opened this issue Jun 13, 2012 · 3 comments
Assignees
Milestone

Comments

@scabug
Copy link

scabug commented Jun 13, 2012

the below match crashes the compiler
it should generate an error instead

Welcome to Scala version 2.10.0-M4 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_31).
Type in expressions to have them evaluated.
Type :help for more information.

scala> trait LogLevelType
defined trait LogLevelType

scala> type LogLevel = Int with LogLevelType
defined type alias LogLevel

scala> final val ErrorLevel = 1.asInstanceOf[Int with LogLevelType]
ErrorLevel: Int with LogLevelType = 1

scala>   final val WarningLevel = 2.asInstanceOf[Int with LogLevelType]
WarningLevel: Int with LogLevelType = 2

scala> def classFor(level: LogLevel): Unit = level match {
     |   case ErrorLevel => ()
     |   case WarningLevel => ()
     | }
@scabug
Copy link
Author

scabug commented Jun 13, 2012

Imported From: https://issues.scala-lang.org/browse/SI-5904?orig=1
Reporter: @adriaanm

@scabug
Copy link
Author

scabug commented Jun 13, 2012

@retronym said (edited on Jun 13, 2012 2:53:06 PM UTC):
For bonus points:

scala> trait LogLevelType
defined trait LogLevelType

scala> type LogLevel = Int with LogLevelType
defined type alias LogLevel

scala>  final val ErrorLevel = 1.asInstanceOf[Int with LogLevelType]
ErrorLevel: Int with LogLevelType = 1

scala> List(ErrorLevel, ErrorLevel)
java.lang.ClassCastException: [I cannot be cast to [Ljava.lang.Object;
        at .<init>(<console>:10)

@scabug
Copy link
Author

scabug commented Jul 23, 2012

@adriaanm said:
since scala/scala#937 this produces an error message rather than a crash

as for bonus points, I'm not sure I'll get to the boss level this way: when you case to unrealizable types that erase to realizable ones, this is what you had coming

In other words, not sure how to fix this without uprooting lots of stuff in uncurry and erasure. I dug around a bit and it seems the Array-logic in uncurry should be operating on erased types. I'll open a separate ticket.

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