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

Ambiguous use of 'buildBlock' #132

Closed
tonyarnold opened this issue Jun 29, 2023 · 5 comments
Closed

Ambiguous use of 'buildBlock' #132

tonyarnold opened this issue Jun 29, 2023 · 5 comments
Labels

Comments

@tonyarnold
Copy link
Contributor

I'm seeing quite a few instances where I use an if let unwrap within the body of a View where Swift can't make up it's mind about which method to use:

For instance:

Nav {
  Anchor {  }

  if let authenticatedUser = context.authenticatedUser {
    Div {  }
  }
}

results in:

HeaderViewComponent.swift:48:74: error: ambiguous use of 'buildBlock'
                    if let authenticatedUser = context.authenticatedUser {
                                                                         ^
HTMLKit/Sources/HTMLKit/Framework/Builders/ContentBuilder.swift:41:24: note: found this candidate
    public static func buildBlock(_ components: T...) -> [T] {
                       ^
HTMLKit/Sources/HTMLKit/Framework/Builders/ContentBuilder.swift:121:24: note: found this candidate
    public static func buildBlock(_ content: [T], _ components: T...) -> [T] {
@mattesmohr mattesmohr added bug Something isn't working needs work rendering v3 labels Jun 29, 2023
@mattesmohr
Copy link
Member

mattesmohr commented Jun 29, 2023

Oh true, this one. I have encountered it multiple times too, but I couldn't fixed without breaking other things. I went nuts.

I was hoping I come up with an idea someday.

I wanted to tackle this one after I am done with the components, but let me see if I can fix it for good at the weekend.

Maybe the new changes of the result builder and new parameter packs, can help me with it.

@mattesmohr
Copy link
Member

mattesmohr commented Jun 29, 2023

If I recall correctly, the result builder doesn't like it that way:

Nav {
  Anchor {  }

  if let authenticatedUser = context.authenticatedUser {
    Div {  }
  }
}

But the opposite way is fine:

Nav {
  if let authenticatedUser = context.authenticatedUser {
    Div {  }
  }

  Anchor {  }
}

So what I did for the moment, is wrapping the if statement in another element.

Nav {
  Div {
      if let authenticatedUser = context.authenticatedUser {
         Div {  }
      }
 }

  Anchor {  }
}

Hope it helps, till I found a solution. Fingers crossed.

@tonyarnold
Copy link
Contributor Author

I'm seeing the same thing for an if statement at the root of a body. Is there a workaround for that that you know about? (I don't want the body to render anything unless a certain condition is met).

@mattesmohr
Copy link
Member

Oh, that's new to me. But I suspect it has something to do, that Body expects a result of [BodyElement]. And the statement returns [Content].

Use the Custom as a workaround.

Custom(name: "body") {
}

I will open a issue for it separately.

@mattesmohr
Copy link
Member

Should be fixed by now. I close the issue.

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

No branches or pull requests

2 participants