This page is no longer maintained — Please continue to the home page at www.scala-lang.org

2.8.1 -> 2.9.0.1: implicit collision

6 replies
Swade Leather
Joined: 2009-01-31,
User offline. Last seen 42 years 45 weeks ago.
Hi all,
I'm trying to update a project to 2.9.0.1 from 2.8.1.  In the process of doing this, I'm getting errors associated with implicits that I haven't seen before:
./src/jq.scala:341: error: type mismatch; found   : String required: ?{val exists: ?}Note that implicit conversions are not applicable because they are ambiguous: both method augmentString in object Predef of type (x: String)scala.collection.immutable.StringOps  and method s2f in package Utils of type (s: String)java.io.File are possible conversion functions from String to ?{val exists: ?}  if (!workdir.exists()) workdir.mkdir();
s2f is defined as:
implicit def s2f(s : String) = new File(s);
This worked in 2.8.1, but now fails (did something changed about how implicits are resolved?). It looks like there's a method exists with a different type signature.  Is there a way around this that would allow me to keep s2f as an implicit?
thanks,wade
Sciss
Joined: 2008-12-17,
User offline. Last seen 28 weeks 5 days ago.
Re: 2.8.1 -> 2.9.0.1: implicit collision

yes, string is treated as an indexedseq of chars:

scala> "gaga".exists
:8: error: missing arguments for method exists in trait IndexedSeqOptimized;
follow this method with `_' if you want to treat it as a partially applied function
"gaga".exists
^
e.g.

scala> "abcdef".exists(_ > 'b')
res2: Boolean = true

you will need to shadow the method name in Predef that goes to StringOps, although then you'd use other of those ops, too. for some weird reason there seem to be too concurrent augments (although with different priorities):

in LowPriorityImplicits (extended by Predef):

implicit def wrapString (s: String): WrappedString

and directly in Predef:

implicit def augmentString (x: String): StringOps

i think this must be a mistake, because StringOps basically implements all the methods of WrappedString, so wrapString is practically ineffective. the problem now is that when you call you method augmentString, wrapString seems to get in your way....

scala> implicit def augmentString( x: String ) = new java.io.File( x )
augmentString: (x: String)java.io.File

scala> "abcdef".exists(_ > 'b')
:9: error: type mismatch;
found : java.lang.String("abcdef")
required: ?{val exists: ?}
Note that implicit conversions are not applicable because they are ambiguous:
both method wrapString in class LowPriorityImplicits of type (s: String)scala.collection.immutable.WrappedString
and method augmentString in object $iw of type (x: String)java.io.File
are possible conversion functions from java.lang.String("abcdef") to ?{val exists: ?}
"abcdef".exists(_ > 'b')
^

so you also need to 'kill' that one:

scala> trait Low { implicit def wrapString( x: String ) = new java.io.File( x )}; object High extends Low { implicit def augmentString( x: String ) = new java.io.File( x )}
defined trait Low
defined module High

scala> import High._
import High._

scala> "abcdef".exists
res0: Boolean = false

...

best, -sciss-

On 6 Jun 2011, at 15:42, S Wade wrote:

> Hi all,
>
> I'm trying to update a project to 2.9.0.1 from 2.8.1. In the process of doing this, I'm getting errors associated with implicits that I haven't seen before:
>
> ./src/jq.scala:341: error: type mismatch;
> found : String
> required: ?{val exists: ?}
> Note that implicit conversions are not applicable because they are ambiguous:
> both method augmentString in object Predef of type (x: String)scala.collection.immutable.StringOps
> and method s2f in package Utils of type (s: String)java.io.File
> are possible conversion functions from String to ?{val exists: ?}
> if (!workdir.exists()) workdir.mkdir();
>
> s2f is defined as:
>
> implicit def s2f(s : String) = new File(s);
>
> This worked in 2.8.1, but now fails (did something changed about how implicits are resolved?). It looks like there's a method exists with a different type signature. Is there a way around this that would allow me to keep s2f as an implicit?
>
> thanks,
> wade
>

dcsobral
Joined: 2009-04-23,
User offline. Last seen 38 weeks 5 days ago.
Re: 2.8.1 -> 2.9.0.1: implicit collision

It worked on 2.8.1?

Welcome to Scala version 2.8.1.final (Java HotSpot(TM) 64-Bit Server
VM, Java 1.6.0_24).
Type in expressions to have them evaluated.
Type :help for more information.

scala> import java.io.File
import java.io.File

scala> implicit def s2f(s : String) = new File(s);
s2f: (s: String)java.io.File

scala> "gaga".exists
:8: error: type mismatch;
found : java.lang.String
required: ?{val exists: ?}
Note that implicit conversions are not applicable because they are ambiguous:
both method s2f in object $iw of type (s: String)java.io.File
and method augmentString in object Predef of type (x:
String)scala.collection.immutable.StringOps
are possible conversion functions from java.lang.String to ?{val exists: ?}
"gaga".exists
^

On Mon, Jun 6, 2011 at 11:42, S Wade wrote:
> Hi all,
> I'm trying to update a project to 2.9.0.1 from 2.8.1.  In the process of
> doing this, I'm getting errors associated with implicits that I haven't seen
> before:
> ./src/jq.scala:341: error: type mismatch;
>  found   : String
>  required: ?{val exists: ?}
> Note that implicit conversions are not applicable because they are
> ambiguous:
>  both method augmentString in object Predef of type (x:
> String)scala.collection.immutable.StringOps
>  and method s2f in package Utils of type (s: String)java.io.File
>  are possible conversion functions from String to ?{val exists: ?}
>   if (!workdir.exists()) workdir.mkdir();
> s2f is defined as:
> implicit def s2f(s : String) = new File(s);
> This worked in 2.8.1, but now fails (did something changed about how
> implicits are resolved?). It looks like there's a method exists with a
> different type signature.  Is there a way around this that would allow me to
> keep s2f as an implicit?
> thanks,
> wade
>

Swade Leather
Joined: 2009-01-31,
User offline. Last seen 42 years 45 weeks ago.
Re: 2.8.1 -> 2.9.0.1: implicit collision
Try it with parens (2.8.1 and 2.9.0.1 included below):
Welcome to Scala version 2.8.1.final (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_24).Type in expressions to have them evaluated. Type :help for more information.
scala> implicit def s2f(s : String) = new java.io.File(s);s2f: (s: String)java.io.File
scala> "Test".exists <console>:7: error: type mismatch; found   : java.lang.String required: ?{val exists: ?}Note that implicit conversions are not applicable because they are ambiguous:  both method s2f in object $iw of type (s: String)java.io.File  and method augmentString in object Predef of type (x: String)scala.collection.immutable.StringOps are possible conversion functions from java.lang.String to ?{val exists: ?}       "Test".exists        ^
scala> "Test".exists()res1: Boolean = false
Welcome to Scala version 2.9.0.1 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_24). Type in expressions to have them evaluated.Type :help for more information.
scala> implicit def s2f(s : String) = new java.io.File(s);s2f: (s: String)java.io.File
scala> "Test".exists<console>:9: error: type mismatch; found   : java.lang.String("Test") required: ?{val exists: ?}Note that implicit conversions are not applicable because they are ambiguous:  both method augmentString in object Predef of type (x: String)scala.collection.immutable.StringOps and method s2f in object $iw of type (s: String)java.io.File are possible conversion functions from java.lang.String("Test") to ?{val exists: ?}        "Test".exists       ^
scala> "Test".exists()<console>:9: error: type mismatch; found   : java.lang.String("Test")  required: ?{val exists: ?}Note that implicit conversions are not applicable because they are ambiguous: both method augmentString in object Predef of type (x: String)scala.collection.immutable.StringOps  and method s2f in object $iw of type (s: String)java.io.File are possible conversion functions from java.lang.String("Test") to ?{val exists: ?}       "Test".exists()        ^



On Mon, Jun 6, 2011 at 5:59 PM, Daniel Sobral <dcsobral [at] gmail [dot] com> wrote:
It worked on 2.8.1?

Welcome to Scala version 2.8.1.final (Java HotSpot(TM) 64-Bit Server
VM, Java 1.6.0_24).
Type in expressions to have them evaluated.
Type :help for more information.

scala> import java.io.File
import java.io.File

scala> implicit def s2f(s : String) = new File(s);
s2f: (s: String)java.io.File

scala> "gaga".exists
<console>:8: error: type mismatch;
 found   : java.lang.String
 required: ?{val exists: ?}
Note that implicit conversions are not applicable because they are ambiguous:
 both method s2f in object $iw of type (s: String)java.io.File
 and method augmentString in object Predef of type (x:
String)scala.collection.immutable.StringOps
 are possible conversion functions from java.lang.String to ?{val exists: ?}
      "gaga".exists
      ^



On Mon, Jun 6, 2011 at 11:42, S Wade <swadenator [at] gmail [dot] com> wrote:
> Hi all,
> I'm trying to update a project to 2.9.0.1 from 2.8.1.  In the process of
> doing this, I'm getting errors associated with implicits that I haven't seen
> before:
> ./src/jq.scala:341: error: type mismatch;
>  found   : String
>  required: ?{val exists: ?}
> Note that implicit conversions are not applicable because they are
> ambiguous:
>  both method augmentString in object Predef of type (x:
> String)scala.collection.immutable.StringOps
>  and method s2f in package Utils of type (s: String)java.io.File
>  are possible conversion functions from String to ?{val exists: ?}
>   if (!workdir.exists()) workdir.mkdir();
> s2f is defined as:
> implicit def s2f(s : String) = new File(s);
> This worked in 2.8.1, but now fails (did something changed about how
> implicits are resolved?). It looks like there's a method exists with a
> different type signature.  Is there a way around this that would allow me to
> keep s2f as an implicit?
> thanks,
> wade
>



--
Daniel C. Sobral

I travel to the future all the time.

Swade Leather
Joined: 2009-01-31,
User offline. Last seen 42 years 45 weeks ago.
Re: 2.8.1 -> 2.9.0.1: implicit collision

Anyone know what's changes in 2.9.0.1 that causes the difference shown below in implicit resolution behavior?

thanks,
wade

On Jun 6, 2011 6:00 PM, "Daniel Sobral" <dcsobral [at] gmail [dot] com> wrote:
> It worked on 2.8.1?
>
> Welcome to Scala version 2.8.1.final (Java HotSpot(TM) 64-Bit Server
> VM, Java 1.6.0_24).
> Type in expressions to have them evaluated.
> Type :help for more information.
>
> scala> import java.io.File
> import java.io.File
>
> scala> implicit def s2f(s : String) = new File(s);
> s2f: (s: String)java.io.File
>
> scala> "gaga".exists
> <console>:8: error: type mismatch;
> found : java.lang.String
> required: ?{val exists: ?}
> Note that implicit conversions are not applicable because they are ambiguous:
> both method s2f in object $iw of type (s: String)java.io.File
> and method augmentString in object Predef of type (x:
> String)scala.collection.immutable.StringOps
> are possible conversion functions from java.lang.String to ?{val exists: ?}
> "gaga".exists
> ^
>
>
>
> On Mon, Jun 6, 2011 at 11:42, S Wade <swadenator [at] gmail [dot] com> wrote:
>> Hi all,
>> I'm trying to update a project to 2.9.0.1 from 2.8.1.  In the process of
>> doing this, I'm getting errors associated with implicits that I haven't seen
>> before:
>> ./src/jq.scala:341: error: type mismatch;
>>  found   : String
>>  required: ?{val exists: ?}
>> Note that implicit conversions are not applicable because they are
>> ambiguous:
>>  both method augmentString in object Predef of type (x:
>> String)scala.collection.immutable.StringOps
>>  and method s2f in package Utils of type (s: String)java.io.File
>>  are possible conversion functions from String to ?{val exists: ?}
>>   if (!workdir.exists()) workdir.mkdir();
>> s2f is defined as:
>> implicit def s2f(s : String) = new File(s);
>> This worked in 2.8.1, but now fails (did something changed about how
>> implicits are resolved?). It looks like there's a method exists with a
>> different type signature.  Is there a way around this that would allow me to
>> keep s2f as an implicit?
>> thanks,
>> wade
>>
>
>
>
> --
> Daniel C. Sobral
>
> I travel to the future all the time.
Seth Tisue
Joined: 2008-12-16,
User offline. Last seen 34 weeks 3 days ago.
Re: 2.8.1 -> 2.9.0.1: implicit collision

On Thu, Jun 9, 2011 at 5:23 AM, S Wade wrote:
> Anyone know what's changes in 2.9.0.1 that causes the difference shown below
> in implicit resolution behavior?

What difference? Daniel's reply shows the same thing happening in 2.8.

dcsobral
Joined: 2009-04-23,
User offline. Last seen 38 weeks 5 days ago.
Re: 2.8.1 -> 2.9.0.1: implicit collision

On Thu, Jun 16, 2011 at 18:16, Seth Tisue wrote:
> On Thu, Jun 9, 2011 at 5:23 AM, S Wade wrote:
>> Anyone know what's changes in 2.9.0.1 that causes the difference shown below
>> in implicit resolution behavior?
>
> What difference? Daniel's reply shows the same thing happening in 2.8.

Maybe it didn't go to the list, but if you try the name with
parenthesis, there is indeed a difference. And, indeed, there was a
change with regards to arity 0 methods -- iirc, paulp wanted to make
the distinction between them and parameterless methods inexistent for
practical purposes, but Martin laid down the law that they are,
indeed, two different beats.

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland