-
Notifications
You must be signed in to change notification settings - Fork 332
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
Namespacing issues with Down "Node" type #242
Comments
Obviously, my workaround is to render Markdown to a String, then include that as 'raw' in my Pointfree Html struct. But I was kinda hoping to get the full safety etc of their library while writing some content in Markdown. |
Minimal project to show the issue: https://github.com/djstevenson/Down-issue-242/ The specific source file of interest is https://github.com/djstevenson/Down-issue-242/blob/main/Sources/SongsToTheSiren/Markdown/HtmlVisitor.swift |
Hey @djstevenson , thanks for getting in touch and for the nice example repo. So this is an interesting problem that I've never come across before. The source of the problem is that the Down module contains a public type called Consider the following code: // Down is the module name
import Down
// You'd think that Down here is referring to the module, but it's actually
// referring to a struct called Down within the Down module. If you cmd + click
// on the word Down you'll see the definition of the struct.
typealias DownNode = Down.Node You're getting the error "Node is not a member type of Down" because Xcode sees that the struct called Unfortunately I couldn't figure out a way for Xcode to refer to the module rather than the struct, without having to change the name of the // In DownAliases.swift
import Down
typealias DownNode = Node
typealias DownText = Text
typealias DownImage = Image
...
// In HtmlAliases.swift
import Html
typealias HtmlNode = Node
... Then you can use those aliases in any other file in your module, even files that import Down and / or Html. Try it out and let me know how you go. And lastly, I don't believe there are stupid questions so don't hesitate to ask any more that you might have, I'm happen to help in any way I can. |
Thank you for the lightning quick response! Unfortunately, I'm still seeing the same error in DownAliases.swift - I've pushed a commit implementing your suggestion to my demo repo. Searching Swift forums and StackOverflow have led me to the conclusion this is a known problem in the current version of Swift, being unable to disambiguate package from type when they are named the same. |
I think I might have cracked it, with DownAliases.swift containing this, which I now realise is probably what you meant to put in your workaround example above:
|
@djstevenson ahhhh yeah, sorry my bad! Indeed I mistyped the code block example, I'll update the comment and close this issue. Feel free to reach out for anything else! |
I really appreciate your help, thank you. |
Looks like SR-898 -- a known language limitation for 5 years. |
I want to build an Html object using Pointfree's https://github.com/pointfreeco/swift-html
and this Down package.
The idea was to use Down to parse Markdown, and to use a "visitor" (as you define in DebugVisitor for testing) - as I visit a node, I generate the corresponding Html node (so, rather than doing Markdown -> String, I'm trying to do Markdown -> [Html.Node])
I have a problem with the name spacing - both Html and Down define a Node type. That's normal - I can specifically refer to their type as Html.Node - but I can't refer to your type as Down.Node
My struct imports both:
Then, a reference to "Node" produces the expected error "'Node' is ambiguous for type lookup in this context", along with:
If I refer to an html type as Html.Node all is fine. But, despite Swift saying "Down.Node" is a candidate, when I use Down.Node I get
I can't seem to get the Down node type namespaced.
Xcode 12.3
Html: 0.3.1 https://github.com/pointfreeco/swift-html
Down: 0.9.4
(Note, I'm relatively new to Swift, so sorry if I'm just being a bit dumb. If so, any pointers towards being less dumb would be gratefully received!)
The text was updated successfully, but these errors were encountered: