-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Disallow Array[Nothing], Array[Null], ... to avoid ClassCastException in some cases #1730
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
Comments
Erasing Array[_ <: X] to Object is very expensive computationally, and it would be surprising for users. So I am much in favor of disallowing Array[Nothing] and Array[Null]. |
One quite radical idea would be to treat |
If we disallow |
Is I have my doubts because in the end there is no class |
Here are a few usages I found in projects I've checked out. Seems fairly rare.
|
Currently in Dotty we have scala> if (false) Array("qwe") else Array()
-- Error: <console>:5:36 -------------------------------------------------------
5 |if (false) Array("qwe") else Array()
| ^
|attempt to take ClassTag of undetermined type for parameter evidence$2 of method apply in object Array @odersky can this issue be closed? This was probably fixed in e34555f |
@nicolasstucki No, as stated in the PR that this commit comes from: #1921 (comment) |
The comment says that we might want to consider disallowing forming a |
`typeSymbol` returns NoSymbol on an intersection type, so our previous check wasn't good enough. See scala#1730 for background.
`typeSymbol` returns NoSymbol on an intersection type, so our previous check wasn't good enough. See scala#1730 for background.
…ference failure (#16492) The first commit generalizes the fix for #1730, the second commit improves inference in a common situation to generate a valid ClassTag rather than emitting an error, fixing the example from #16328 (comment).
`typeSymbol` returns NoSymbol on an intersection type, so our previous check wasn't good enough. See scala#1730 for background.
See also https://issues.scala-lang.org/browse/SI-7453
In
scalac
:In dotty, thankfully:
But still in dotty:
We either need to disallow
Array[Nothing]
,Array[Null]
, etc or we need to eraseArray[_ <: X]
toObject
instead of[X;
.It would also be much nicer if we could infer the empty array above to have type
Array[String]
instead ofArray[Nothing]
, I don't know what prevents us from doing this currently.The text was updated successfully, but these errors were encountered: