Is it a bug? Implicit map interferes with nonEmpty call
Gallus Anonimus <[email protected]> Sat, 22 Oct 2016 05:53:53 -0700 (PDT)
| Newsgroups | gmane.comp.lang.scala |
|---|---|
| Message-ID | <[email protected]> |
------=_Part_165_285432810.1477140833721
Content-Type: multipart/alternative;
boundary="----=_Part_166_1680449102.1477140833722"
------=_Part_166_1680449102.1477140833722
Content-Type: text/plain; charset=UTF-8
Hi,
In following code:
object TheApp {
def main(args : Array[String]) {
implicit val innocentMap = Map("foo" -> Set("bar"))
"baz".nonEmpty
}
}
instead of computing expected true as "baz" string is non empty
results in "java.util.NoSuchElementException: key not found: baz"
I tested it on 2.10, 2.11.8, 2.12.RC2 with same results.
The implicit innocentMap is the culprit.
After decompiling "baz".nonEmpty looks like this:
((TraversableOnce)innocentMap.apply("baz")).nonEmpty();
Can anyone tell me why innocentMap.apply is magically called here?
Highly unexpected behaviour. If innocentMap has different type like:
implicit val innocentMap = Map("foo" -> ("bar"))
code behaves as expected.
Sholud I report scala library bug?
--
You received this message because you are subscribed to the Google Groups "scala-language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/d/optout.
------=_Part_166_1680449102.1477140833722
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Hi,<br>In following code:<br><br><div style=3D"background-=
color: rgb(250, 250, 250); border-color: rgb(187, 187, 187); border-style: =
solid; border-width: 1px; overflow-wrap: break-word;" class=3D"prettyprint"=
><code class=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"c=
olor: #008;" class=3D"styled-by-prettify">object</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #606;" =
class=3D"styled-by-prettify">TheApp</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">{</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"><br>=C2=A0 <br>=C2=A0 </span><span style=3D"color: #008;" class=3D"s=
tyled-by-prettify">def</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"> main</span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">ar=
gs </span><span style=3D"color: #660;" class=3D"styled-by-prettify">:</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span st=
yle=3D"color: #606;" class=3D"styled-by-prettify">Array</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">[</span><span style=3D"color=
: #606;" class=3D"styled-by-prettify">String</span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">])</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">{</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #008;" class=3D"styl=
ed-by-prettify">implicit</span><span style=3D"color: #000;" class=3D"styled=
-by-prettify"> val innocentMap </span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"styled=
-by-prettify"> </span><span style=3D"color: #606;" class=3D"styled-by-prett=
ify">Map</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(<=
/span><span style=3D"color: #080;" class=3D"styled-by-prettify">"foo&q=
uot;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">-></span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #606;" class=3D"styled-by-prettify">Set</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #080;=
" class=3D"styled-by-prettify">"bar"</span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">))</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color: =
#080;" class=3D"styled-by-prettify">"baz"</span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">.</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify">nonEmpty<br>=C2=A0 </span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">}</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"><br>=C2=A0 <br></span><span style=3D"color:=
#660;" class=3D"styled-by-prettify">}</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"><br></span></div></code></div>instead of comput=
ing expected true as "baz" string is non empty<br>results in &quo=
t;java.util.NoSuchElementException: key not found: baz"<code class=3D"=
prettyprint"><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=
</span></code>I tested it on 2.10, 2.11.8, 2.12.RC2 with same results.<br>T=
he implicit innocentMap is the culprit.<br>After decompiling "baz"=
;.nonEmpty looks like this:<br><div style=3D"background-color: rgb(250, 250=
, 250); border-color: rgb(187, 187, 187); border-style: solid; border-width=
: 1px; overflow-wrap: break-word;" class=3D"prettyprint"><code class=3D"pre=
ttyprint"><div class=3D"subprettyprint"><span style=3D"color: #660;" class=
=3D"styled-by-prettify">((</span><span style=3D"color: #606;" class=3D"styl=
ed-by-prettify">TraversableOnce</span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">)</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify">innocentMap</span><span style=3D"color: #660;" class=3D"styled-=
by-prettify">.</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy">apply</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(=
</span><span style=3D"color: #080;" class=3D"styled-by-prettify">"baz&=
quot;</span><span style=3D"color: #660;" class=3D"styled-by-prettify">)).</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify">nonEmpty</sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">();</span></di=
v></code></div><br>Can anyone tell me why innocentMap.apply is magically ca=
lled here?<br>Highly unexpected behaviour. If innocentMap has different typ=
e like:<br><div style=3D"background-color: rgb(250, 250, 250); border-color=
: rgb(187, 187, 187); border-style: solid; border-width: 1px; overflow-wrap=
: break-word;" class=3D"prettyprint"><code class=3D"prettyprint"><div class=
=3D"subprettyprint"><span style=3D"color: #008;" class=3D"styled-by-prettif=
y">implicit</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
> val innocentMap </span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
> </span><span style=3D"color: #606;" class=3D"styled-by-prettify">Map</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span s=
tyle=3D"color: #080;" class=3D"styled-by-prettify">"foo"</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">-></span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">(</span><span style=3D"color: #080;" class=
=3D"styled-by-prettify">"bar"</span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">))</span></div></code></div>code behaves as ex=
pected.<br><br>Sholud I report scala library bug?<br></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;scala-language" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:[email protected]">scal=
[email protected]</a>.<br />
For more options, visit <a href=3D"https://groups.google.com/d/optout">http=
s://groups.google.com/d/optout</a>.<br />
------=_Part_166_1680449102.1477140833722--
------=_Part_165_285432810.1477140833721--