Re: When are scala macros expanded?
Jeremy Smith <[email protected]>
| Newsgroups | gmane.comp.lang.scala |
|---|---|
| Message-ID | <[email protected]> |
Hi Andrew, I understand that this is an edge case, and probably not a good idea to begin with. However, it's still an interesting question: if a method calls implicitly[Something], but that method is never called, can you consider the implicit Something to be required? Should compilation then fail if it isn't provided? The compiler has no problem checking for the implicit - the issue (if you can call it that) is that the compiler checks it eagerly during compilation of the class, not at the call site of the method which calls implicitly[Something]. On Wednesday, June 17, 2015 at 8:10:44 PM UTC-7, Andrew Phillips wrote: > > Hi Jeremy > > Without having spent much time trying to come up with a creative approach, > I would be surprised if what you're trying to do were possible. > > If I understand your problem statement correctly, you're trying to add a > condition to a method defined on an interface "after the fact:" an > additional (implicit) parameter, in this case. Yet this condition is only > supposed to be checked for by the compiler if the implementation class of > the interface happens to be *your* specific class. Which would seem to > require that the compiler know up front what the *runtime* class of the > implementation will be. > > If I write: > > val myObj: SomeInterface = ... > myObj.foo(...) > > I would imagine that the compiler can *only* verify that my attempt to > call foo is compatible with the definition of foo in SomeInterface, > i.e. the static type of myObj. I don't see how, at compile time, we would > be able to say: "Ah, if myObj in this case happens to be an instance of > SpecialImplOfSomeInterface, we need to check for an extra > implicit/parameter/parameter list/whatever." > > Curious to see what other participants in this thread will come up with! > > Regards > > ap > -- 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.