-
Notifications
You must be signed in to change notification settings - Fork 28
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
Correctly disambiguate conflicting type names between the module itself and external modules. #111
Conversation
return importableTypes to referencedTypes.values.map { it.moduleName }.toSet() | ||
} | ||
|
||
companion object { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kdubb I moved away from this style as it is a bit hard to carry additional information we need between the first pass and the second pass.
It was not being super helpful anyway and I did it initially to mirror KotlinPoet, but we are not KotlinPoet. I also thought by doing this we were avoiding writing the file twice but that is not true either because we use NullAppendable
.
|
||
struct SomeType { | ||
|
||
var yet_another_module_order: [yet_another_module.SortOrder] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test fails without my change. It outputs var yet_another_module_order: [SortOrder]
which conflicts with the same module SortOrder
that is added here.
cab8f0e
to
59ada1f
Compare
return if (importedTypes[typeName.topLevelTypeName().simpleName]?.count() == 1 && importedTypes.values.flatMap { it }.any { it == topLevelTypeName }) { | ||
return if (topLevelTypeName.moduleName.isNotEmpty() && sameModuleReferencedTypes.contains(topLevelTypeName.simpleName)) { | ||
typeName.canonicalName | ||
} else if (importedTypes[topLevelTypeName.simpleName]?.count() == 1 && importedTypes.values.flatMap { it }.any { it == topLevelTypeName }) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This changed from [typeName.topLevelTypeName().simpleName]
to [topLevelTypeName.simpleName]
did not need to calculate it again since its already stored above.
59ada1f
to
4c23025
Compare
@@ -29,7 +29,8 @@ private val NO_MODULE = String() | |||
internal class CodeWriter( | |||
out: Appendable, | |||
private val indent: String = DEFAULT_INDENT, | |||
internal val importedTypes: Map<String, List<DeclaredTypeName>> = emptyMap(), | |||
private val importedTypes: Map<String, List<DeclaredTypeName>> = emptyMap(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need to be internal
23ecaa7
to
afd998f
Compare
…lf and external modules.
afd998f
to
e519eb4
Compare
@@ -376,7 +379,9 @@ internal class CodeWriter( | |||
*/ | |||
private fun resolveImport(typeName: DeclaredTypeName): String { | |||
val topLevelTypeName = typeName.topLevelTypeName() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add a val topLevelSimpleName = topLevelTypeName.simpleName
since you need it a few times?
sameModuleReferencedTypes = sameModuleReferencedTypes | ||
) | ||
codeWriter.use { | ||
emit(codeWriter, referencedModules = referencedModules) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is now wrapped in a .use
so close
gets called automatically.
Tested Wire with this change and our internal monorepo and its ✅ ✅ ✅ |
If a type exists within a module that is being used by it and the same type exists in another module we do not properly disambiguate between them.
That is because we only keep track of
referenceTypeNames
that include amoduleName
. This change collects the types used by the same module and properly disambiguates.