Re: Seq :+ repeat parameter

som-snytt <[email protected]> Thu, 14 Apr 2016 14:54:59 -0700 (PDT)
Newsgroups gmane.comp.lang.scala
Message-ID <[email protected]>
paulp would say, Xlint would have told you not to do that.

$ scala -Xlint
Welcome to Scala 2.11.8 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_60).
Type in expressions for evaluation. Or try :help.

scala> scala> val seq = Seq(1, 2, 3)

// Detected repl transcript. Paste more, or ctrl-D to finish.

seq: Seq[Int] = List(1, 2, 3)

scala> val seq2 = seq :+ (4, 5, 6)
seq2: Seq[Any] = List(1, 2, 3, (4,5,6))
// Replaying 2 commands from transcript.

scala> val seq = Seq(1, 2, 3)
seq: Seq[Int] = List(1, 2, 3)

scala> val seq2 = seq :+ (4, 5, 6)
<console>:12: warning: Adapting argument list by creating a 3-tuple: this 
may not be what you want.
        signature: SeqLike.:+[B >: A, That](elem: B)(implicit bf: 
scala.collection.generic.CanBuildFrom[Repr,B,That]): That
  given arguments: 4, 5, 6
 after adaptation: SeqLike.:+((4, 5, 6): (Int, Int, Int))
       val seq2 = seq :+ (4, 5, 6)
                      ^
seq2: Seq[Any] = List(1, 2, 3, (4,5,6))


scala> :quit

I suppose it suppresses -Ywarn-infer-any, or no it doesn't actually warn 
for the previous example.

scala> List(1, "abc")
<console>:12: warning: a type was inferred to be `Any`; this may indicate a 
programming error.

On Thursday, April 7, 2016 at 6:29:07 AM UTC-7, Rich Oliver wrote:
>
> On Thursday, 7 April 2016 13:49:18 UTC+1, Oliver Ruebenacker wrote:
>>
>>
>>      Hello,
>>
>>   Is it possible that your code does not do what one might think it does?
>>
>> scala> val seq = Seq(1, 2, 3)
>> seq: Seq[Int] = List(1, 2, 3)
>>
>> scala> val seq2 = seq :+ (4, 5, 6)
>> seq2: Seq[Any] = List(1, 2, 3, (4,5,6))
>>
>>      Best, Oliver
>>
>
> Hi yes you're right. I was forgetting Scala's insanely hyperactive type 
> inference. Well at least I'm not alone, it drove Paul Phillips to despair. 
> Will this madness get worse with type unions? 
>

-- 
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.