diff options
author | Paul Phillips <paulp@improving.org> | 2012-09-14 13:09:18 -0700 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2012-09-14 13:09:18 -0700 |
commit | b61a2e31d27e6496ad5ac96758fe8003719cacb0 (patch) | |
tree | 21297a4989122d4018cafd1dcbe408e0d290b4e2 /test/files/neg | |
parent | 493d16306cf0e836da9c77a4768dd42620dd1a72 (diff) | |
parent | ddb3b889b5fa55760167d9995d2f1549e2542b71 (diff) | |
download | scala-b61a2e31d27e6496ad5ac96758fe8003719cacb0.tar.gz scala-b61a2e31d27e6496ad5ac96758fe8003719cacb0.tar.bz2 scala-b61a2e31d27e6496ad5ac96758fe8003719cacb0.zip |
Merge pull request #1290 from retronym/ticket/no-implicit-to-anyref
A little cleanup along the Any to AnyRef trail.
Diffstat (limited to 'test/files/neg')
-rw-r--r-- | test/files/neg/no-implicit-to-anyref.check | 28 | ||||
-rw-r--r-- | test/files/neg/no-implicit-to-anyref.scala | 29 |
2 files changed, 57 insertions, 0 deletions
diff --git a/test/files/neg/no-implicit-to-anyref.check b/test/files/neg/no-implicit-to-anyref.check new file mode 100644 index 0000000000..d94b57a30a --- /dev/null +++ b/test/files/neg/no-implicit-to-anyref.check @@ -0,0 +1,28 @@ +no-implicit-to-anyref.scala:11: error: type mismatch; + found : Int(1) + required: AnyRef +Note: an implicit exists from scala.Int => java.lang.Integer, but +methods inherited from Object are rendered ambiguous. This is to avoid +a blanket implicit which would convert any scala.Int to any AnyRef. +You may wish to use a type ascription: `x: java.lang.Integer`. + 1: AnyRef + ^ +no-implicit-to-anyref.scala:17: error: type mismatch; + found : Any + required: AnyRef + (null: Any): AnyRef + ^ +no-implicit-to-anyref.scala:21: error: type mismatch; + found : AnyVal + required: AnyRef + (0: AnyVal): AnyRef + ^ +no-implicit-to-anyref.scala:27: error: type mismatch; + found : Test.AV + required: AnyRef +Note that AV extends Any, not AnyRef. +Such types can participate in value classes, but instances +cannot appear in singleton types or in reference comparisons. + new AV(0): AnyRef + ^ +four errors found diff --git a/test/files/neg/no-implicit-to-anyref.scala b/test/files/neg/no-implicit-to-anyref.scala new file mode 100644 index 0000000000..3e3d373e38 --- /dev/null +++ b/test/files/neg/no-implicit-to-anyref.scala @@ -0,0 +1,29 @@ +// 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 + } +} |