diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2014-01-27 10:29:28 +0100 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2014-01-27 10:44:48 +0100 |
commit | 327eea839e97e1d7cac92aa9cd61e3338d12cb12 (patch) | |
tree | 27c96fc40658a947216b61fab6b6da4956c6cdbd /test/files/neg/no-implicit-to-anyref-any-val.scala | |
parent | a5b0fc49e517d1c63d22f9909ac9bed0552ed466 (diff) | |
download | scala-327eea839e97e1d7cac92aa9cd61e3338d12cb12.tar.gz scala-327eea839e97e1d7cac92aa9cd61e3338d12cb12.tar.bz2 scala-327eea839e97e1d7cac92aa9cd61e3338d12cb12.zip |
Prohibit views targeting AnyVal
Library changes in Scala 2.10 mean that we are left with the
unfortunate situation of admitting:
scala> "": AnyVal
res0: AnyVal =
We already have explicit checks in place to prevent views
targeting `AnyRef`. This commit balances this out by prohibiting
`AnyVal`, as well.
The enclosed test shows that this case is now prevented. If multiple
implicits views are applicable, the ambiguity error is still raised;
these check comes right at the end. Maybe that ought to be changed,
but I don't think it matters too much.
I've also disabled this prohibition under -Xsource:2.10.
Diffstat (limited to 'test/files/neg/no-implicit-to-anyref-any-val.scala')
-rw-r--r-- | test/files/neg/no-implicit-to-anyref-any-val.scala | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/test/files/neg/no-implicit-to-anyref-any-val.scala b/test/files/neg/no-implicit-to-anyref-any-val.scala new file mode 100644 index 0000000000..f5daf541af --- /dev/null +++ b/test/files/neg/no-implicit-to-anyref-any-val.scala @@ -0,0 +1,33 @@ +// Checks that the state of standard implicits in Predef._ and scala._ +// doesn't allow us to unambiguously and implicitly convert AnyVal +// and subtypes to AnyRef. +// +// In the days before value classes, this was precariously held be +// the competing implicits Any => StringAdd and Any => StringFormat. +// Since then, these have both become value classes, but seeing as +// this happened simultaneously, we're still okay. +object Test { + locally { + 1: AnyRef + } + + locally { + // before this test case was added and ContextErrors was tweaked, this + // emitted: "Note that Any extends Any, not AnyRef." + (null: Any): AnyRef + } + + locally { + (0: AnyVal): AnyRef + } + + class AV(val a: Int) extends AnyVal + + locally { + new AV(0): AnyRef + } + + "": AnyVal + + new Object() : AnyVal +} |