--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-user+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
> "cannot convert null to Int".
Yes that msg would be nicer, but perhaps still a bit strange as one might wonder why it should try to convert at all (esp when assigning null to a reference type doesn't imply conversion). Why try to convert anyway, when it is just a semantic issue that value classes can't be null?
Anyway, beginners will have difficulties with error messages at the beginning anyway so this might not be more difficult than many other error messages. I guess it is rather difficult to establish a consistent terminology across all error messages...
Is it worth it to file an issue on the error message, do you think?
Thanks,
/B
Hi Oliver
Many thanks for your help!
Is it false to say that "AnyVal values cannot be null"?
> The point is that there never can be an implicit conversion from Null to Int
My argument is about regularity, I guess. What I meant was that in other situations the compiler does not seem to consider conversions, as error messages are simply "type mismatch" even if there in theory *could* be a conversion, e.g.. in this REPL-interaction (rather untypical, but for the sake of example):
Welcome to Scala 2.11.8 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_66).
Type in expressions for evaluation. Or try :help.
scala> class MyRefClass
defined class MyRefClass
scala> val r: MyRefClass = null
r: MyRefClass = null
scala> val i: MyRefClass = 42
<console>:12: error: type mismatch;
found : Int(42)
required: MyRefClass
val i: MyRefClass = 42
^
scala> implicit def intToMyRefClass(i: Int) = new MyRefClass
warning: there was one feature warning; re-run with -feature for details
intToMyRefClass: (i: Int)MyRefClass
scala> val i: MyRefClass = 42
i: MyRefClass = MyRefClass@6f195bc3