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

Add support for checked casts in debug mode #858

Closed
Duhemm opened this issue Jun 21, 2017 · 2 comments
Closed

Add support for checked casts in debug mode #858

Duhemm opened this issue Jun 21, 2017 · 2 comments

Comments

@Duhemm
Copy link
Contributor

Duhemm commented Jun 21, 2017

The following code compiles fine, but its behavior is different on the JVM and on Native:

object Main {
  def main(args: Array[String]): Unit = {
    println(0.asInstanceOf[String]) // Prints `0`, should throw `ClassCastException`
    println("" + 0.asInstanceOf[String]) // Prints ``, should throw `ClassCastException`
  }
}

On Native, the first println will print 0, but it should throw an exception.
The second println will print an empty line, but it should throw an exception too.

@densh densh changed the title 0.asInstanceOf[String] should fail at runtime Add support for checked casts in debug mode Jun 27, 2017
@densh
Copy link
Member

densh commented Jun 27, 2017

Casts are unchecked on purpose in release mode. We wanted to make them checked in debug for a while now, but there was no issue for it.

@densh densh added this to the Backlog milestone Jun 27, 2017
matil019 added a commit to matil019/scala-native that referenced this issue Jun 27, 2017
Array[E].toArray[T](Array[T]) is still not compliant because
it is specified to throw ArrayStoreException if not T >: E but
it doesn't.

This can't be fixed now because there is no compile-time type
information and runtime cast is not type-checked. See scala-native#858.
matil019 added a commit to matil019/scala-native that referenced this issue Jun 27, 2017
Array[E].toArray[T](Array[T]) is not still compliant because
it is specified to throw ArrayStoreException if not T >: E but
it doesn't.

This can't be fixed now because there is no compile-time type
information and runtime cast is not type-checked. See scala-native#858.
matil019 added a commit to matil019/scala-native that referenced this issue Jun 27, 2017
Array[E].toArray[T](Array[T]) is not still compliant because
it is specified to throw ArrayStoreException if not T >: E but
it doesn't.

This can't be fixed now because there is no compile-time type
information and runtime cast is not type-checked. See scala-native#858.
densh pushed a commit that referenced this issue Jun 27, 2017
* Throw more exceptions as specified in the JDK Javadoc

Array[E].toArray[T](Array[T]) is not still compliant because
it is specified to throw ArrayStoreException if not T >: E but
it doesn't.

This can't be fixed now because there is no compile-time type
information and runtime cast is not type-checked. See #858.

* Change the type of ArrayList.inner to Array[Any]

Found that Scala(-Native) can handle Array[Any] just fine.
asoltysik pushed a commit to asoltysik/scala-native that referenced this issue Jul 14, 2017
…tive#878)

* Throw more exceptions as specified in the JDK Javadoc

Array[E].toArray[T](Array[T]) is not still compliant because
it is specified to throw ArrayStoreException if not T >: E but
it doesn't.

This can't be fixed now because there is no compile-time type
information and runtime cast is not type-checked. See scala-native#858.

* Change the type of ArrayList.inner to Array[Any]

Found that Scala(-Native) can handle Array[Any] just fine.
@densh densh modified the milestones: Backlog, Duplicate Jan 9, 2018
@densh
Copy link
Member

densh commented Jan 9, 2018

Superseded by #1140

@densh densh closed this as completed Jan 9, 2018
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