Factors that prevent implicit conversions to be found

78 views
Skip to first unread message

Johannes Rudolph

unread,
May 21, 2015, 10:57:35 AM5/21/15
to scala-l...@googlegroups.com
Hi,

in the akka-http/spray routing DSL there's a case where an implicit
conversion isn't found in some cases (mostly deterministic per compile
run) for this line:

parameter('color)

where parameter's argument should be of type `ParamMagnet` and the
implicit conversion is defined in ParamMagnet's companion object.

There's quite some logic involved behind the scenes to convert a
Symbol to a ParamMagnet implicit. The strange thing is that you can
make it compile by adding a line just mentioning the type
`ParamMagnet` above the problematic line:

e.g.

type X = akka.http.scaladsl.server.directives.ParameterDirectives.ParamMagnet
parameter('color)

or

val x: akka.http.scaladsl.server.directives.ParameterDirectives.ParamMagnet
= null
parameter('color)


Adding the line below the problematic one doesn't help. I know it's
not the first time I had such an issue but I cannot remember if I
found a solution or not before.

`-Xlog-implicits` doesn't show anything. The compilation problem
occurs with Scala 2.10.x.

Any ideas?

Thanks,
Johannes

martin odersky

unread,
May 21, 2015, 11:27:53 AM5/21/15
to scala-l...@googlegroups.com
Could it be a case of an implicit with a missing result type?

- Martin
> --
> 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 scala-languag...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
Martin Odersky
EPFL

Johannes Rudolph

unread,
May 21, 2015, 11:31:51 AM5/21/15
to scala-l...@googlegroups.com
On Thu, May 21, 2015 at 5:27 PM, martin odersky <martin....@epfl.ch> wrote:
> Could it be a case of an implicit with a missing result type?

Ah, yes, that could be. It's a path-dependent result type, so it
wasn't spelled out. I'll see what happens if it is spelled out.

Thanks,

--
Johannes

-----------------------------------------------
Johannes Rudolph
http://virtual-void.net

Johannes Rudolph

unread,
May 22, 2015, 3:10:18 AM5/22/15
to scala-l...@googlegroups.com
Thanks again Martin, the missing result types were exactly the
problem. I guess this also explains the sometimes observed
non-deterministic cases where the order of compilation units during
incremental were another factor that would allow the compilation to
succeed in a few cases.

Johannes

Simon Schäfer

unread,
May 22, 2015, 3:50:30 AM5/22/15
to scala-l...@googlegroups.com


On 05/22/2015 09:09 AM, Johannes Rudolph wrote:
> Thanks again Martin, the missing result types were exactly the
> problem. I guess this also explains the sometimes observed
> non-deterministic cases where the order of compilation units during
> incremental were another factor that would allow the compilation to
> succeed in a few cases.
Actually I thought the compiler is already emitting a warning in such
cases but after looking at the corresponding ticket
https://issues.scala-lang.org/browse/SI-5265 it doesn't seem to be
implemented yet. I must have dreamed it - or I used another linting tool
that supports the functionality.

martin odersky

unread,
May 22, 2015, 3:58:33 AM5/22/15
to scala-l...@googlegroups.com
On Fri, May 22, 2015 at 9:50 AM, Simon Schäfer <ma...@antoras.de> wrote:
>
>
> On 05/22/2015 09:09 AM, Johannes Rudolph wrote:
>>
>> Thanks again Martin, the missing result types were exactly the
>> problem. I guess this also explains the sometimes observed
>> non-deterministic cases where the order of compilation units during
>> incremental were another factor that would allow the compilation to
>> succeed in a few cases.
>
> Actually I thought the compiler is already emitting a warning in such cases
> but after looking at the corresponding ticket
> https://issues.scala-lang.org/browse/SI-5265 it doesn't seem to be
> implemented yet. I must have dreamed it - or I used another linting tool
> that supports the functionality.
>>
It's an error in the dotty compiler. - Martin

>>
>> Johannes
>>
>> On Thu, May 21, 2015 at 5:31 PM, Johannes Rudolph
>> <johannes...@googlemail.com> wrote:
>>>
>>> On Thu, May 21, 2015 at 5:27 PM, martin odersky <martin....@epfl.ch>
>>> wrote:
>>>>
>>>> Could it be a case of an implicit with a missing result type?
>>>
>>> Ah, yes, that could be. It's a path-dependent result type, so it
>>> wasn't spelled out. I'll see what happens if it is spelled out.
>>>
>>> Thanks,
>>>
>>> --
>>> Johannes
>>>
>>> -----------------------------------------------
>>> Johannes Rudolph
>>> http://virtual-void.net
>>
>>
>>
>

Som Snytt

unread,
May 22, 2015, 10:49:46 AM5/22/15
to scala-l...@googlegroups.com
Modulo bugs, it is verbose if error:

 Note: implicit method x is not applicable here because it comes after the application point and it lacks an explicit result type


--

Johannes Rudolph

unread,
May 22, 2015, 10:58:47 AM5/22/15
to scala-l...@googlegroups.com
On Fri, May 22, 2015 at 9:50 AM, Simon Schäfer <ma...@antoras.de> wrote:
>> Thanks again Martin, the missing result types were exactly the
>> problem. I guess this also explains the sometimes observed
>> non-deterministic cases where the order of compilation units during
>> incremental were another factor that would allow the compilation to
>> succeed in a few cases.
>
> Actually I thought the compiler is already emitting a warning in such cases
> but after looking at the corresponding ticket
> https://issues.scala-lang.org/browse/SI-5265 it doesn't seem to be
> implemented yet. I must have dreamed it - or I used another linting tool
> that supports the functionality.

It seems there are several "levels" of possible conditions. In one
case the compiler is able to show you the message, in this case,
however, it didn't even detect that it should have looked there. If
you take the error message for granted the second condition is at
least a bug of error reporting then.

The case in question was here btw: https://github.com/akka/akka/pull/17552/files
Reply all
Reply to author
Forward
0 new messages