2 May 2012 19:27
No feature warning for implicit objects which extend Function1
While triaging some bugs today, I noticed:
object Test {
class Foo
class RichFoo
implicit def enrich(foo: Foo) = new RichFoo
def bar(rich: RichFoo) {}
bar(new Foo)
}
With the "-feature" flag gives:
t5197.scala:10: warning: implicit conversion method enrich should be enabled
by making the implicit value language.implicitConversions visible.
This can be achieved by adding the import clause 'import
language.implicitConversions'
or by setting the compiler option -language:implicitConversions.
See the Scala docs for value scala.language.implicitConversions for a
discussion
why the feature should be explicitly enabled.
implicit def enrich(foo: Foo) = new RichFoo
^
one warning found
as expected. But:
object Test {
class Foo
class RichFoo
implicit object enrich extends (Foo => RichFoo) {
def apply(foo: Foo) = new RichFoo
}
def bar(rich: RichFoo) {}
bar(new Foo)
}
yields no warning. Is this expected?
--
--
Aleksandar Prokopec,
Doctoral Assistant
LAMP, IC, EPFL
http://people.epfl.ch/aleksandar.prokopec
RSS Feed