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
Type aliases should be scoped to the containing type #38
Comments
my changes in #39 will help since we will be able to access parent types from children, I've few ideas how we can implement this but not sure if you started on this or is this for the picking? |
I didn't start on that, just though about how to implement that so you can pick it if you want. What were your ideas? I was thinking that to parse type aliases inside the type is not a big deal, we just need to get a syntax map for not the whole content, but just for the type body portion. Then we can store discovered type aliases in the collection in the The problem then is how to parse global type aliases. Probably we need to check if typealias token is outside of any types body ranges (I guess we can get that from __parserData). Another problem is what to do with private type aliases. The thing is that it's possible to have different private typealiases with the same name in different extensions. struct MyStruct {}
extension MyStruct {
private typealias MyAlias = Int
private var myInt: MyAlias { return 0 }
}
extension MyStruct {
private typealias MyAlias = String
private var myString: MyAlias { return "" }
} So to find proper type in this case we need to do that before we extend type with these extensions... But to be honest I'm not sure we should handle that case as these variables will not be accessible from generated code. But then maybe we should ignore everything what is private? Like private methods, variables, contained types. |
Pretty much the same idea, it seems you have thought this through more than I did though, want to try this out? I think it makes sense to skip scanning private variables since you are right they wouldn't be accessible, if it's not private variable but has private typealias we can replace it with right type then |
Ok, I'll go for it then. |
ah right, it doesn't compile otherwise 👍 |
With current implementation type aliases with the same name defined in different types will override each other. That breaks the usual case of defining type alias to conform to protocol.
In this case type of
rawValue
property ofFooEnum
will be detected incorrectly asBar
asRawValue = Bar
will overrideRawValue = Foo
The text was updated successfully, but these errors were encountered: