Type of expression is ambiguous error

I have the following code:

let phxUpdateTree: Elements = walk(elements: innerHtml) {(node) -> Node in
    return applyPhxUpdate(DOM.attribute(node, "phx-update"), htmlTree, node)

The walk function is overloaded with two function signatures:

static func walk(elements: Elements, _ closure: (_ node: Node)throws -> Node)throws -> Elements {


static func walk(node: Node, _ closure: (_ node: Node)throws -> Node)throws -> Node {

and I am getting the error Type of expression is ambiguous without more context

My understanding is that it wouldn't have been ambiguous due to the type constraint (element is of type Element which is a subclass of Node) so I changed to the specific labels and still get the same error which makes me suspect the error is something else but I'm not seeing it.

The only wrong think I can see is that walk throws but in the first snippet it isn't marked with try. You should do something like:

do {
  let phxUpdateTree: Elements = try walk(elements: innerHtml) { node in
} catch { ... }

The actual error was on the applyPhxUpdate call but the editor was showing the line above as having the error. I guess it was just showing the LOC the closure started.

Terms of Service

Privacy Policy

Cookie Policy