GUIDJsExp.guidToTuple not working as implicit

54 views
Skip to first unread message

Diego Medina

unread,
May 28, 2012, 10:50:55 AM5/28/12
to Lift
Hi,

As I make my way removing deprecated methods from Lift (the framework
repo for now), I decided to check the examples repo, to make sure we
are not using any of the deleted methods there.
While doing that, I ended up with this error:

[error] /Users/diego.medina/Desktop/work/lift/examples/combo/example/src/main/scala/net/liftweb/example/snippet/AjaxForm.scala:53:
constructor cannot be instantiated to expected type;
[error] found : (T1, T2)
[error] required: net.liftweb.http.GUIDJsExp
[error] val (name, js) = ajaxCall(JE.JsRaw("this.value"),
[error] ^

I know David added GUIDJsExp [1] so that we no longer have to call
._2.toJsCmd, and I see there is a implicit conversion :

object GUIDJsExp {
implicit def guidToTuple(in: GUIDJsExp): (String, JsExp) = (in.guid, in.exp)

but somehow the implicit is not kicking in here, if I change the line:

def show(xhtml: Group): NodeSeq = {
val (name, js) = ajaxCall(JE.JsRaw("this.value"),
s => After(200, replace(s)))

for



def show(xhtml: Group): NodeSeq = {
val (name, js) = GUIDJsExp.guidToTuple(ajaxCall(JE.JsRaw("this.value"),
s => After(200, replace(s))))

then it compiles just fine. Any ideas of what is going on here?

[1] https://github.com/lift/framework/blob/master/web/webkit/src/main/scala/net/liftweb/http/SHtml.scala#L2242

Thanks

Diego





--
Diego Medina
Lift/Scala Developer
di...@fmpwizard.com
http://www.fmpwizard.com

David Pollak

unread,
May 28, 2012, 10:52:46 AM5/28/12
to lif...@googlegroups.com
The types of name and js are not known.

val (name: String, js: JsCmd) = ajaxCall(...)

should work.

--
Lift, the simply functional web framework: http://liftweb.net
Code: http://github.com/lift
Discussion: http://groups.google.com/group/liftweb
Stuck? Help us help you: https://www.assembla.com/wiki/show/liftweb/Posting_example_code



--
Visi.Pro, Cloud Computing for the Rest of Us http://visi.pro
Lift, the simply functional web framework http://liftweb.net


Diego Medina

unread,
May 28, 2012, 11:09:18 AM5/28/12
to lif...@googlegroups.com
I ended up with this:

val (name, js): (String, JsExp) = ajaxCall(JE.JsRaw("this.value"),
s => After(200, replace(s)))

but I get a warning:

non variable type-argument String in type pattern (String,
net.liftweb.http.js.JsExp) is unchecked since it is eliminated by
erasure
[warn] val (name, js): (String, JsExp) = ajaxCall(JE.JsRaw("this.value"),

, if I use:


val (name: String, js: JsCmd) = ajaxCall(JE.JsRaw("this.value"),
s => After(200, replace(s)))
or
val (name: String, js: JsExp) = ajaxCall(JE.JsRaw("this.value"),
s => After(200, replace(s)))


I still get:
[error] /Users/diego.medina/Desktop/work/lift/examples/combo/example/src/main/scala/net/liftweb/example/snippet/AjaxForm.scala:53:
constructor cannot be instantiated to expected type;
[error] found : (T1, T2)
[error] required: net.liftweb.http.GUIDJsExp
[error] val (name: String, js: JsCmd) = ajaxCall(JE.JsRaw("this.value"),
[error] ^

I guess because there is type erasure, we cannot just annotate the
type inside the tuple.

Thanks

Diego

David Pollak

unread,
May 29, 2012, 12:54:30 PM5/29/12
to lif...@googlegroups.com
On Mon, May 28, 2012 at 8:09 AM, Diego Medina <di...@fmpwizard.com> wrote:
I ended up with this:

   val (name, js): (String, JsExp) = ajaxCall(JE.JsRaw("this.value"),
                             s => After(200, replace(s)))

but I get a warning:

non variable type-argument String in type pattern (String,
net.liftweb.http.js.JsExp) is unchecked since it is eliminated by
erasure
[warn]     val (name, js): (String, JsExp) = ajaxCall(JE.JsRaw("this.value"),

, if I use:


   val (name: String, js: JsCmd) = ajaxCall(JE.JsRaw("this.value"),
                             s => After(200, replace(s)))
or
   val (name: String, js: JsExp) = ajaxCall(JE.JsRaw("this.value"),
                             s => After(200, replace(s)))


I still get:
[error] /Users/diego.medina/Desktop/work/lift/examples/combo/example/src/main/scala/net/liftweb/example/snippet/AjaxForm.scala:53:
constructor cannot be instantiated to expected type;
[error]  found   : (T1, T2)
[error]  required: net.liftweb.http.GUIDJsExp
[error]     val (name: String, js: JsCmd) = ajaxCall(JE.JsRaw("this.value"),
[error]           ^

I guess because there is type erasure, we cannot just annotate the
type inside the tuple.

Actually, the syntax I proposed was wrong... I guess I should have tested it first.

The syntax you showed that led to the type erasure warning is the correct syntax.

The type erasure warning comes from the fact that assigning to a tuple turns the statement in a pattern match.  When you designate the type of the items in the pattern, the pattern matcher code gets cranky because of type erasure and emits the warning.  If the type inferencer/checker were more robust, we would not get the warning.

There's another option:
 val (name, js) = ajaxCall(JE.JsRaw("this.value"), s => After(200, replace(s))): (String, JsExp) 

That tells the type inferencer what the type is on the right hand side so the left-hand side gets inferred correctly, the implicit conversion happens correctly, and there's no type erasure in the pattern matcher.

Damian Helme

unread,
Feb 17, 2013, 4:05:56 AM2/17/13
to lif...@googlegroups.com
thanks guys for the discussion, I just got bitten by that.
Reply all
Reply to author
Forward
0 new messages