Sourcery icon indicating copy to clipboard operation
Sourcery copied to clipboard

Distinguish types with the same name from different modules

Open ilyapuchka opened this issue 7 years ago • 11 comments

Currently multiple targets support has a limitation that it is not able to distinguish types with the same name coming from different modules. If types with the same name from different modules will be scanned together they will be merged into type scanned first, as they are mapped by their name, which does not contain module name. Also there is no way to access such types in the templates.

ilyapuchka avatar Apr 09 '17 19:04 ilyapuchka

As far as I can see from the code, we can close this issue, could you confirm it please?

Antondomashnev avatar Aug 22 '17 14:08 Antondomashnev

Nope, it was never done and to be honest, I'm not sure how to approach this, especially in terms of templates api.

ilyapuchka avatar Aug 22 '17 14:08 ilyapuchka

If types with the same name from different modules will be scanned together they will be merged into type scanned first, as they are mapped by their name, which does not contain module name.

Wasn't it resolved with module and globalName properties on Type? I can see in Composer that it has the modules dictionary to collect types by module name.

Antondomashnev avatar Aug 22 '17 15:08 Antondomashnev

it collects, but I don't think it properly distinguish types mentioned in scanned code. Because if you have two types named the same from different modules what type we should assign to the declaration depends on the current scope of the file, what is being imported. Unless you use full type name. And other issues like how to mention these types in the templates. If you mention it by type name without module which one we should return? Currently we just override one type with another in types collections.

ilyapuchka avatar Aug 22 '17 15:08 ilyapuchka

If you mention it by type name without module which one we should return? Currently we just override one type with another in types collections.

I think this should be done on the client's shoulders. So in the template there should be somehow information which module to use. But I got the point that this is not done yet.

Antondomashnev avatar Aug 22 '17 15:08 Antondomashnev

I got the same issue with my project. In the sources, I saw there is a module in Type, which is not specified in docs. If I use sources for scanning files, the module is always nil. To have the correct value of module I need to use project in configuration. But now I have another issue. In docs written You can use several project or target objects to scan multiple targets from one project or to scan multiple projects, but in fact it only scans the last defined target. I have tried several configurations, like:

project:
  file: test.xcodeproj
  target:
    name: test
templates:
  - Templates
output:
  path: CodeGenerated
project:
  file: Pods/Pods.xcodeproj
  target:
    name: SomeFramework
templates:
  - Templates
output:
  path: CodeGenerated

Also

project:
  file: test.xcodeproj
  target:
    name: test
project:
  file: Pods/Pods.xcodeproj
  target:
    name: SomeFramework
templates:
  - Templates
output:
  path: CodeGenerated

rubensamsonyanauto1 avatar Dec 12 '18 10:12 rubensamsonyanauto1

@rubensamsonyanauto1 I believe what you described is a different problem, can you please create a new issue for it?

ilyapuchka avatar Dec 12 '18 10:12 ilyapuchka

@ilyapuchka Sure, will do. From my comment it's not obvious, but I came here, because I had types with the same name from different modules and to fix the issue, wanted to add module name in front of the type name and got the issue I described :)

rubensamsonyanauto1 avatar Dec 12 '18 14:12 rubensamsonyanauto1

Any updates on this issue?

MaximKotliar avatar Mar 02 '21 12:03 MaximKotliar

Sourcery have been doing lookups by module for a while now but there will be big changes in next releases anyway so if it doesn't do something atm then it won't until that AST rewrite happens

krzysztofzablocki avatar Mar 02 '21 20:03 krzysztofzablocki

Are there any updates on this issue?

schmiter avatar Jun 22 '23 18:06 schmiter