Any operator in Scala ending with a colon :
is defined on the right operand.
So, when you write 1::2
means ::
should be defined on 2
i.e on Int
which is not the case.
Nil
is a Value of List
and has a method defined ::
on it. So when you write 1 :: 2 :: Nil
it is evaluated as (Nil.::(2)).::(1)
.