I'll think about it... instead of using copy, you could also try to use
constructor directly in the macro...
But just one point: be really careful when you choose macro instead of a
classic language pattern. I really consider macro as a tool but not as a
patch to solve problems that shouldn't be solved in this way... (I don't
say your choice is bad, just to consider macros very precisely ;) )
regards
Pascal
On Mon, Nov 19, 2012 at 2:36 AM, Daniel Dietrich <cafeb...@googlemail.com>wrote:
Thank you. It was very interesting to investigate the new Scala macros & reflection features. I see also the pros/cons of changing the default behavior of the compiler - and with that the semantics of the Scala language. One important thing of Scala is its conciseness. With macros things can be done even more concise. That was also my driver in this case. I'm curious if folks will create a Scala_A, Scala_B, ... in the near future - à la 'pimp my language'...
"equals the user jay" in {
val profile = Profile("Jay Cain")
val settings = Settings()
val jay = User("cain....@gmail.com", profile, settings, "hash", None, false)
val userJson = Json.toJson(jay)
val user = Json.fromJson(userJson)
...
}
}
}
when I run the test I get the following error:
[error] /Users/cainj/sandbox/pong/test/json/ApplicationSpec.scala:30: diverging implicit expansion for type play.api.libs.json.Reads[T]
[error] starting with method ArrayReads in trait DefaultReads
[error] val user = Json.fromJson(userJson) [error] ^
Any insight would be helpful. I'm tried the play master and play-2.1-RC-1
On Monday, November 19, 2012 9:13:29 AM UTC-7, Daniel Dietrich wrote:
> Thank you. It was very interesting to investigate the new Scala macros & > reflection features. I see also the pros/cons of changing the default > behavior of the compiler - and with that the semantics of the Scala > language. One important thing of Scala is its conciseness. With macros > things can be done even more concise. That was also my driver in this case. > I'm curious if folks will create a Scala_A, Scala_B, ... in the near future > - à la 'pimp my language'...
> "equals the user jay" in {
> val profile = Profile("Jay Cain")
> val settings = Settings()
> val jay = User("cain....@gmail.com", profile, settings, "hash", None
> , false)
> val userJson = Json.toJson(jay)
> val user = Json.fromJson(userJson)
> ...
> }
> }
> }
> when I run the test I get the following error:
> [error] /Users/cainj/sandbox/pong/test/json/ApplicationSpec.scala:30: > diverging implicit expansion for type play.api.libs.json.Reads[T]
> [error] starting with method ArrayReads in trait DefaultReads
> [error] val user = Json.fromJson(userJson) > [error] ^
> Any insight would be helpful. I'm tried the play master and play-2.1-RC-1
> Thx,
> Jay
> On Monday, November 19, 2012 9:13:29 AM UTC-7, Daniel Dietrich wrote:
>> Thank you. It was very interesting to investigate the new Scala macros & >> reflection features. I see also the pros/cons of changing the default >> behavior of the compiler - and with that the semantics of the Scala >> language. One important thing of Scala is its conciseness. With macros >> things can be done even more concise. That was also my driver in this case. >> I'm curious if folks will create a Scala_A, Scala_B, ... in the near future >> - à la 'pimp my language'...
object AddressBean extends Controller with RestTrait {
implicit val addressWrites = Json.writes[Address]
implicit val addressReads = Json.reads[Address]
}
warning: value and is not a member of play.api.libs.json.Reads[Option[Int]] Note: implicit value addressReads is not applicable here because it comes after the application point and it lacks an explicit result type
I'm wondering if you have added anything else to fix these...
Basically I have to make this JSON stuff to work with 2.1-RC1 because my project uses scala 2.10 so can't go back to 2.09... Is there any chance to solve this issue?
> object AddressBean extends Controller with RestTrait {
> implicit val addressWrites = Json.writes[Address]
> implicit val addressReads = Json.reads[Address]
> }
> warning: value and is not a member of
> play.api.libs.json.Reads[Option[Int]] Note: implicit value addressReads is
> not
> applicable here because it comes after the application point and it lacks
> an explicit result type
> I'm wondering if you have added anything else to fix these...
> Basically I have to make this JSON stuff to work with 2.1-RC1 because my
> project uses scala 2.10 so can't go back to 2.09... Is there any chance to
> solve this issue?
> Thanks!
> On Saturday, November 24, 2012 8:43:57 AM UTC+2, Daniel Dietrich wrote:
>> Hi Jay,
>> it should work with the 2.1 master / rc1 too. Just add these imports and
>> to implicit val's:
>> Anyway, as of this discussion the json stuff is currently subject of
>> refactoring...
>> object AddressBean extends Controller with RestTrait {
>> implicit val addressWrites = Json.writes[Address]
>> implicit val addressReads = Json.reads[Address] >> }
>> warning: value and is not a member of >> play.api.libs.json.Reads[Option[Int]] Note: implicit value addressReads is >> not >> applicable here because it comes after the application point and it >> lacks an explicit result type
>> I'm wondering if you have added anything else to fix these...
>> Basically I have to make this JSON stuff to work with 2.1-RC1 because my >> project uses scala 2.10 so can't go back to 2.09... Is there any chance to >> solve this issue?
>> Thanks!
>> On Saturday, November 24, 2012 8:43:57 AM UTC+2, Daniel Dietrich wrote:
>>> Hi Jay,
>>> it should work with the 2.1 master / rc1 too. Just add these imports and >>> to implicit val's:
>>> Anyway, as of this discussion the json stuff is currently subject of >>> refactoring...
On Saturday, November 17, 2012 12:44:39 AM UTC+1, Daniel Dietrich wrote:
> Pascal,
> do you think your pull request will make it into Play 2.1-final since it > is already tagged as RC1?
> On Friday, November 16, 2012 5:30:54 PM UTC+1, Pascal wrote:
>> Hello all,
>> After some macro headaches, I finally succeeded in adding fully qualified >> classes everywhere and also embedding functional.syntax._ import in >> generated code.
Interrestingly enouth, I get the same error when I do the mapping manually, without using the macro magic! See that gist https://gist.github.com/4177529
I'm sure there is a better solution than renaming all my companion objects ;) But what could it be?
On Friday, November 30, 2012 7:03:31 PM UTC+1, Thibault wrote:
> I'm getting a compiler error when the case class has a companion object. I > use scala 2.10.0-RC3 and the very latest Play20, built from master branch.
> Excellent job with Play 2.1, thanks a bunch! I'm now rewritting > http://lichess.org with all that new goodness, it's a lot of fun.
> On Saturday, November 17, 2012 12:44:39 AM UTC+1, Daniel Dietrich wrote:
>> Pascal,
>> do you think your pull request will make it into Play 2.1-final since it >> is already tagged as RC1?
>> On Friday, November 16, 2012 5:30:54 PM UTC+1, Pascal wrote:
>>> Hello all,
>>> After some macro headaches, I finally succeeded in adding fully >>> qualified classes everywhere and also embedding functional.syntax._ import >>> in generated code.
> I'm getting a compiler error when the case class has a companion object. I
> use scala 2.10.0-RC3 and the very latest Play20, built from master branch.
> Excellent job with Play 2.1, thanks a bunch! I'm now rewritting
> http://lichess.org with all that new goodness, it's a lot of fun.
> On Saturday, November 17, 2012 12:44:39 AM UTC+1, Daniel Dietrich wrote:
>> Pascal,
>> do you think your pull request will make it into Play 2.1-final since it
>> is already tagged as RC1?
>> On Friday, November 16, 2012 5:30:54 PM UTC+1, Pascal wrote:
>>> Hello all,
>>> After some macro headaches, I finally succeeded in adding fully
>>> qualified classes everywhere and also embedding functional.syntax._ import
>>> in generated code.
As soon as you create object for case class, case class hidden features are
overriden by compiler...
Concerning the macro, I think we could improve it a bit and go around this
problem.
Pascal
Le 30 nov. 2012 19:22, "Thibault" <thibault.duples...@gmail.com> a écrit :
> Interrestingly enouth, I get the same error when I do the mapping
> manually, without using the macro magic! See that gist
> https://gist.github.com/4177529
> I'm sure there is a better solution than renaming all my companion objects
> ;) But what could it be?
> On Friday, November 30, 2012 7:03:31 PM UTC+1, Thibault wrote:
>> I'm getting a compiler error when the case class has a companion object.
>> I use scala 2.10.0-RC3 and the very latest Play20, built from master branch.
>> Excellent job with Play 2.1, thanks a bunch! I'm now rewritting
>> http://lichess.org with all that new goodness, it's a lot of fun.
>> On Saturday, November 17, 2012 12:44:39 AM UTC+1, Daniel Dietrich wrote:
>>> Pascal,
>>> do you think your pull request will make it into Play 2.1-final since it
>>> is already tagged as RC1?
>>> On Friday, November 16, 2012 5:30:54 PM UTC+1, Pascal wrote:
>>>> Hello all,
>>>> After some macro headaches, I finally succeeded in adding fully
>>>> qualified classes everywhere and also embedding functional.syntax._ import
>>>> in generated code.
On Saturday, December 1, 2012 12:15:41 AM UTC+1, Pascal wrote:
> If you use Foo.apply, it should work.
> As soon as you create object for case class, case class hidden features > are overriden by compiler...
> Concerning the macro, I think we could improve it a bit and go around this > problem.
> Pascal
> Le 30 nov. 2012 19:22, "Thibault" <thibault....@gmail.com <javascript:>> > a écrit :
>> Interrestingly enouth, I get the same error when I do the mapping >> manually, without using the macro magic! See that gist >> https://gist.github.com/4177529
>> I'm sure there is a better solution than renaming all my companion >> objects ;) But what could it be?
>> On Friday, November 30, 2012 7:03:31 PM UTC+1, Thibault wrote:
>>> I'm getting a compiler error when the case class has a companion object. >>> I use scala 2.10.0-RC3 and the very latest Play20, built from master branch.
>>> Excellent job with Play 2.1, thanks a bunch! I'm now rewritting >>> http://lichess.org with all that new goodness, it's a lot of fun.
>>> On Saturday, November 17, 2012 12:44:39 AM UTC+1, Daniel Dietrich wrote:
>>>> Pascal,
>>>> do you think your pull request will make it into Play 2.1-final since >>>> it is already tagged as RC1?
>>>> On Friday, November 16, 2012 5:30:54 PM UTC+1, Pascal wrote:
>>>>> Hello all,
>>>>> After some macro headaches, I finally succeeded in adding fully >>>>> qualified classes everywhere and also embedding functional.syntax._ import >>>>> in generated code.
> Indeed manual mapping with (Foo.apply _) is working.
> I tried the macro style with scala 2.10.0-RC2, and no difference, I get > the same compiler error.
> On Saturday, December 1, 2012 12:15:41 AM UTC+1, Pascal wrote:
>> If you use Foo.apply, it should work.
>> As soon as you create object for case class, case class hidden features >> are overriden by compiler...
>> Concerning the macro, I think we could improve it a bit and go around >> this problem.
>> Pascal
>> Le 30 nov. 2012 19:22, "Thibault" <thibault....@gmail.com> a écrit :
>>> Interrestingly enouth, I get the same error when I do the mapping >>> manually, without using the macro magic! See that gist >>> https://gist.github.com/4177529
>>> I'm sure there is a better solution than renaming all my companion >>> objects ;) But what could it be?
>>> On Friday, November 30, 2012 7:03:31 PM UTC+1, Thibault wrote:
>>>> I'm getting a compiler error when the case class has a companion >>>> object. I use scala 2.10.0-RC3 and the very latest Play20, built from >>>> master branch.
>>>> Excellent job with Play 2.1, thanks a bunch! I'm now rewritting >>>> http://lichess.org with all that new goodness, it's a lot of fun.
>>>> On Saturday, November 17, 2012 12:44:39 AM UTC+1, Daniel Dietrich wrote:
>>>>> Pascal,
>>>>> do you think your pull request will make it into Play 2.1-final since >>>>> it is already tagged as RC1?
>>>>> On Friday, November 16, 2012 5:30:54 PM UTC+1, Pascal wrote:
>>>>>> Hello all,
>>>>>> After some macro headaches, I finally succeeded in adding fully >>>>>> qualified classes everywhere and also embedding functional.syntax._ import >>>>>> in generated code.
On Sunday, December 2, 2012 12:35:59 AM UTC+1, Grégory Bougeard wrote:
> As @mandubian told me, there is a limitation on case class containing one > and only one attribute.
> Maybe this is your case...
> Le samedi 1 décembre 2012 18:04:20 UTC+1, Thibault a écrit :
>> Indeed manual mapping with (Foo.apply _) is working.
>> I tried the macro style with scala 2.10.0-RC2, and no difference, I get >> the same compiler error.
>> On Saturday, December 1, 2012 12:15:41 AM UTC+1, Pascal wrote:
>>> If you use Foo.apply, it should work.
>>> As soon as you create object for case class, case class hidden features >>> are overriden by compiler...
>>> Concerning the macro, I think we could improve it a bit and go around >>> this problem.
>>> Pascal
>>> Le 30 nov. 2012 19:22, "Thibault" <thibault....@gmail.com> a écrit :
>>>> Interrestingly enouth, I get the same error when I do the mapping >>>> manually, without using the macro magic! See that gist >>>> https://gist.github.com/4177529
>>>> I'm sure there is a better solution than renaming all my companion >>>> objects ;) But what could it be?
>>>> On Friday, November 30, 2012 7:03:31 PM UTC+1, Thibault wrote:
>>>>> I'm getting a compiler error when the case class has a companion >>>>> object. I use scala 2.10.0-RC3 and the very latest Play20, built from >>>>> master branch.
>>>>> Excellent job with Play 2.1, thanks a bunch! I'm now rewritting >>>>> http://lichess.org with all that new goodness, it's a lot of fun.
>>>>> On Saturday, November 17, 2012 12:44:39 AM UTC+1, Daniel Dietrich >>>>> wrote:
>>>>>> Pascal,
>>>>>> do you think your pull request will make it into Play 2.1-final since >>>>>> it is already tagged as RC1?
>>>>>> On Friday, November 16, 2012 5:30:54 PM UTC+1, Pascal wrote:
>>>>>>> Hello all,
>>>>>>> After some macro headaches, I finally succeeded in adding fully >>>>>>> qualified classes everywhere and also embedding functional.syntax._ import >>>>>>> in generated code.
On Monday, December 3, 2012 8:57:58 PM UTC, Thibault wrote:
> No it's the same thing with several attributes. Sorry for the delay, I'm > travelling at the moment.
> On Sunday, December 2, 2012 12:35:59 AM UTC+1, Grégory Bougeard wrote:
>> As @mandubian told me, there is a limitation on case class containing one >> and only one attribute.
>> Maybe this is your case...
>> Le samedi 1 décembre 2012 18:04:20 UTC+1, Thibault a écrit :
>>> Indeed manual mapping with (Foo.apply _) is working.
>>> I tried the macro style with scala 2.10.0-RC2, and no difference, I get >>> the same compiler error.
>>> On Saturday, December 1, 2012 12:15:41 AM UTC+1, Pascal wrote:
>>>> If you use Foo.apply, it should work.
>>>> As soon as you create object for case class, case class hidden features >>>> are overriden by compiler...
>>>> Concerning the macro, I think we could improve it a bit and go around >>>> this problem.
>>>> Pascal
>>>> Le 30 nov. 2012 19:22, "Thibault" <thibault....@gmail.com> a écrit :
>>>>> Interrestingly enouth, I get the same error when I do the mapping >>>>> manually, without using the macro magic! See that gist >>>>> https://gist.github.com/4177529
>>>>> I'm sure there is a better solution than renaming all my companion >>>>> objects ;) But what could it be?
>>>>> On Friday, November 30, 2012 7:03:31 PM UTC+1, Thibault wrote:
>>>>>> I'm getting a compiler error when the case class has a companion >>>>>> object. I use scala 2.10.0-RC3 and the very latest Play20, built from >>>>>> master branch.
>>>>>> Excellent job with Play 2.1, thanks a bunch! I'm now rewritting >>>>>> http://lichess.org with all that new goodness, it's a lot of fun.
>>>>>> On Saturday, November 17, 2012 12:44:39 AM UTC+1, Daniel Dietrich >>>>>> wrote:
>>>>>>> Pascal,
>>>>>>> do you think your pull request will make it into Play 2.1-final >>>>>>> since it is already tagged as RC1?
>>>>>>> On Friday, November 16, 2012 5:30:54 PM UTC+1, Pascal wrote:
>>>>>>>> Hello all,
>>>>>>>> After some macro headaches, I finally succeeded in adding fully >>>>>>>> qualified classes everywhere and also embedding functional.syntax._ import >>>>>>>> in generated code.
On Thu, Jan 3, 2013 at 3:35 PM, deVIAntCoDE <hnoclel...@gmail.com> wrote:
> Yes I have the same problem as well. I have had to rename my companion
> objects as well. What is the progress on the issue though?
> I found this ticket relating to it but no comment on it so far.
> On Monday, December 3, 2012 8:57:58 PM UTC, Thibault wrote:
>> No it's the same thing with several attributes. Sorry for the delay, I'm
>> travelling at the moment.
>> On Sunday, December 2, 2012 12:35:59 AM UTC+1, Grégory Bougeard wrote:
>>> As @mandubian told me, there is a limitation on case class containing
>>> one and only one attribute.
>>> Maybe this is your case...
>>> Le samedi 1 décembre 2012 18:04:20 UTC+1, Thibault a écrit :
>>>> Indeed manual mapping with (Foo.apply _) is working.
>>>> I tried the macro style with scala 2.10.0-RC2, and no difference, I get
>>>> the same compiler error.
>>>> On Saturday, December 1, 2012 12:15:41 AM UTC+1, Pascal wrote:
>>>>> If you use Foo.apply, it should work.
>>>>> As soon as you create object for case class, case class hidden
>>>>> features are overriden by compiler...
>>>>> Concerning the macro, I think we could improve it a bit and go around
>>>>> this problem.
>>>>> Pascal
>>>>> Le 30 nov. 2012 19:22, "Thibault" <thibault....@gmail.com> a écrit :
>>>>>> I'm sure there is a better solution than renaming all my companion
>>>>>> objects ;) But what could it be?
>>>>>> On Friday, November 30, 2012 7:03:31 PM UTC+1, Thibault wrote:
>>>>>>> I'm getting a compiler error when the case class has a companion
>>>>>>> object. I use scala 2.10.0-RC3 and the very latest Play20, built from
>>>>>>> master branch.
>>>>>>> Excellent job with Play 2.1, thanks a bunch! I'm now rewritting
>>>>>>> http://lichess.org with all that new goodness, it's a lot of fun.
>>>>>>> On Saturday, November 17, 2012 12:44:39 AM UTC+1, Daniel Dietrich
>>>>>>> wrote:
>>>>>>>> Pascal,
>>>>>>>> do you think your pull request will make it into Play 2.1-final
>>>>>>>> since it is already tagged as RC1?
>>>>>>>> On Friday, November 16, 2012 5:30:54 PM UTC+1, Pascal wrote:
>>>>>>>>> Hello all,
>>>>>>>>> After some macro headaches, I finally succeeded in adding fully
>>>>>>>>> qualified classes everywhere and also embedding functional.syntax._ import
>>>>>>>>> in generated code.