Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lens cannot deduce setter from this getter #174

Open
AlexPeret opened this issue Apr 25, 2018 · 4 comments
Open

Lens cannot deduce setter from this getter #174

AlexPeret opened this issue Apr 25, 2018 · 4 comments

Comments

@AlexPeret
Copy link

hi!

I'm facing the following message while trying to use the Lens function:

erro FS9001: Macro error in WebSharper.UI.Macros+LensFunc.TranslateCall: Cannot deduce setter from this getter

After testing it on a debug project, I figure it is working. The main difference between both projects is the failing one references WebSharper.UI assembly (WebSharper.UI.4.2.1.86\lib\net461\WebSharper.UI.dll).

After removing such reference, my code breaks due UI.Next namespace not defined.

In summary, the failing project uses:

open WebSharper
open WebSharper.UI
open WebSharper.UI.Html  // not defined
open WebSharper.UI.Client  // not defined

and the working project uses:

open WebSharper
open WebSharper.UI.Next
open WebSharper.UI.Next.Client
open WebSharper.UI.Next.Html

I recall changing the namespace of UI.Next lib after migrating to WebSharper 4.2 and I'm not sure now what to do.

Should I use the original namespace and get rid of WebSharper.UI.dll or is it a bug on Macro module (WS 4.2)?

Thanks,
Alex

@AlexPeret
Copy link
Author

Adding to it, below the list of assemblies both projects reference to:

Failing Project

  • WebSharper.UI.Next (WebSharper.UI.Next.4.2.0.187)
  • WebSharper.UI.Next.CSharp (WebSharper.UI.Next.4.2.0.187)
  • WebSharper.UI.Next.Templating (WebSharper.UI.Next.4.2.0.187)
  • WebSharper.UI.Next.Templating.Common (WebSharper.UI.Next.4.2.0.187)
  • WebSharper.UI.Next.Templating.Runtime (WebSharper.UI.Next.4.2.0.187)
  • WebSharper.UI.Templating (WebSharper.UI.4.2.1.86)
  • WebSharper.UI.Templating.Common (WebSharper.UI.4.2.1.86)
  • WebSharper.UI.Templating.Runtime (WebSharper.UI.4.2.1.86)

Working (debug) project

  • WebSharper.UI.Next (WebSharper.UI.Next.4.2.0.187)
  • WebSharper.UI.Next.CSharp (WebSharper.UI.Next.4.2.0.187)
  • WebSharper.UI.Next.Templating (WebSharper.UI.Next.4.2.0.187)
  • WebSharper.UI.Next.Templating.Common (WebSharper.UI.Next.4.2.0.187)
  • WebSharper.UI.Next.Templating.Runtime (WebSharper.UI.Next.4.2.0.187)

I've tried removing all references to WebSharper.UI.Next.*.dll family, but issue remains.

@Tarmil
Copy link
Member

Tarmil commented May 2, 2018

You definitely need to either only use WebSharper.UI.Next.* assemblies and namespaces, or only WebSharper.UI.*.

What does your call to Lens look like, and the types involved?

@AlexPeret
Copy link
Author

>> What does your call to Lens look like, and the types involved?

Looks like this issue relates to templating system. The snippet below raises the exception:

    type template = Templating.Template<"ListModelTest.html">

    let ListModelTest () =
        let aliases = 
            ListModel.Create (fun a -> a.Key) [ { Key = 1; Value = "Bill" }; { Key = 2; Value = "Joe" } ]
        
        let items =
            aliases.View
            |> Doc.BindSeqCachedView (fun aliasV ->
                template.EditItem()
                    .Value(Lens aliasV.V.Value)
                    .Doc())
        items

This is the template file (ListModelTest.html):

<div class="table-responsive">
    <table class="table table-striped table-bordered table-hover">
        <thead>
            <tr>
                <th>Value</th>
            </tr>
        </thead>
        <tbody ws-hole="ListContainer">

            <tr ws-template="EditItem">
                <td>
                    <input class="form-control" type="text" ws-var="Value" />
                </td>
            </tr>

        </tbody>
    </table>
</div>

Thanks,
Alex

@Tarmil
Copy link
Member

Tarmil commented May 7, 2018

Oh, right. For Lens, you need to use .V on a Var<'T>, but here you're using it on a View<'T>. The way you can obtain a Var here is by using Doc.BindListModelLens (or equivalently, the DocLens method on your ListModel) instead of Doc.BindSeqCachedView:

        let items =
            aliases
            |> Doc.BindListModelLens (fun _ aliasVar ->
                template.EditItem()
                    .Value(Lens aliasVar.V.Value)
                    .Doc())

I'll work on improving the error message so that this is clearer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants